Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • firepol 125 posts 173 karma points
    Feb 20, 2013 @ 15:39
    firepol
    0

    MVC custom controller (without creating document type)?

    Hi,

    I just upgraded to umbraco 6 hoping to use some MVC4...

    in the Custom controllers documentation I see that I can create a HomeController, but to make it work I need to create in umbaco a document type called "Home".

    Is it possible to create some custom controllers without creating a document type in umbraco?

    My goal is to add to my mvc4 project a few special views not related to umbraco content.

    Note: in an asp.net visual studio project (web application) containing the umbraco installation I can achieve this: I just create a folder called "custom", add "custom" in the umbracoReservedPaths in the web,config, and then add html files, aspx file etc. would be nice to be able to add some Models, Views and Controllers the same way too. E.g. I need this to build a form and save the data in a custom table in my database.

    Thx for letting me know.

  • Andreas Iseli 150 posts 427 karma points
    Feb 21, 2013 @ 11:03
    Andreas Iseli
    1

    Does the controller returns a rendered view? The just create a partial view with an appropriate SurfaceController and call the other actions directly on the page you are. I have created such a controller to return a JsonResult for my contact form.

    On the other hand it should be possible to create your own controller based on an MvcController and adding custom routing. But I've not tried that yet.

  • Jeroen Breuer 4861 posts 12135 karma points MVP 3x admin c-trib
    Feb 21, 2013 @ 12:36
  • firepol 125 posts 173 karma points
    May 30, 2013 @ 09:09
    firepol
    0

    Hi Jeroen, hi all,

    SOLVED. Here I share my results.

    I already know how to use the Surface Controller. Following the Mvc - Creating Html Forms I could create a Model, a Controller and a Partial View (Form.cshtml).

    I have a "Home" Document Type with a Home.cshtml view, as explained in the Custom Controller documentation.

    I hava a Surface Controller for my Form, called FormSurfaceController and a "Index" ActionResult with a "hello world" returned as content.

    What -at moment of writing this post- was not clear, is how to browse/access an ActionResult created inside of a Home Controller, I mean which route would be the good one to access it. The Home hijacking was totally not related to what I needed to do. The Home Controller is to hijack pages of a specific document type.

    In an updated version of the Surface Controller documentation, I finally found the answer to my needs...

    My needs to sum up:

    • I don't want any document types, I need to create a "stand-alone" page and access it via a specific url
    • As programming in MVC I was expecting a nice route such as /Controller/Action not something like blabla.aspx.

    I had to create a SurfaceController and understand which one was the route (the link) to access it, the correct route in my case was:

    http://localhost:64734/umbraco/surface/FormSurface/Index

    I will try the Plugin based controllers for backend modules, they seem perfect for that purpose.

    Please keep updating the official documentation, it's -I think- the main point of reference for developers. It's not really the best to search in google for every possible solution, at best, all best practices should be well documented in the official documentation...

    So thanks again, Umbraco rocks and hopefully the documentation will rock too. In this moment of writing, the docs I linked above look really good. Thank you.

  • Tim Geyssens 6561 posts 15372 karma points MVP 2x c-trib
    May 30, 2013 @ 09:34
    Tim Geyssens
    0

    Well in that case you just need a standard mvc controller and register the route you want

    Here is an example of registering a custom route https://github.com/TimGeyssens/BundlingAndMinificationForTheMasses/blob/master/BundlingAndMinificationForTheMasses/Umbraco/StartUpHandlers.cs

    https://github.com/TimGeyssens/BundlingAndMinificationForTheMasses/blob/master/BundlingAndMinificationForTheMasses/App_Start/RouteConfig.cs

    And you'll need to make sure that umbraco ignores that path by adding it to the web.config umbracoReservedPaths app setting

     

  • firepol 125 posts 173 karma points
    Apr 14, 2014 @ 13:30
    firepol
    0

    Update for who is reading this now. With umbraco 6.1.x (MVC mode) I could create a surface controller called "TestSurfaceController". I do not have any document type called test.

    I just created a view under views\testsurface\index.cshtml and voila my controller works as expected. Cool

    Note, the url to access the index method in the testsurfacecontroller is: /umbraco/surface/testsurface/index

  • Tom 713 posts 952 karma points
    Jul 02, 2014 @ 03:56
    Tom
    0

    Hi Tim,

    Just wondering if you're using a custom route and controllers for a section of the site with the forms auth cookies still apply from the umbraco membership?

    Cheers,

    Tom

  • firepol 125 posts 173 karma points
    Jul 02, 2014 @ 09:59
    firepol
    0

    Hi Tom, why don't you just try it and let us know? I'm curious too ;)

Please Sign in or register to post replies

Write your reply to:

Draft