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.
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.
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 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.
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.
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
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?
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.
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.
Here is an example how I use the SurfaceController: http://our.umbraco.org/forum/developers/api-questions/37894-new-Dynamic(id)-and-new-Node(id)-equiv-in-v6?p=2#comment139546
Jeroen
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 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.
Comment author was deleted
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
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
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
Hi Tom, why don't you just try it and let us know? I'm curious too ;)
is working on a reply...