Creating a custom Controller and View in Umbraco with MVC ?
I m new to Umbraco, have installed Umbacro CMS 7 in my MVC application and doing some test / learning work.
I have created a new controller named Home2, please note I don't have a doc type for Home2. I want to create non Umbraco view/ pages that can work with Umbraco.
On running I m getting below error:
Below is my code for Controller and view, please guide what I should do to create custom controllers and views that can work with Umbraco ? Do I need to create document type even for non Umbraco types ?
Controller:
namespace Web.Controllers
{
public class Home2Controller : Umbraco.Web.Mvc.RenderMvcController
{
//
// GET: /Home/
public override ActionResult Index(RenderModel model)
{
//Do some stuff here, then return the base method
return base.Index(model);
}
}
}
Did you create a documenttype Home2? The umbraco MVC controller logic work with convention over configuration
As for navigation/routing. If you create a document with documenttype Home2 as the root document. It will render the document with the default template if you navigate to localhost:xxx/
Is it necessary to create document type ? I mean I don't want to manage this through Umbraco, just want to directly code and mange it. Yet my MVC project has installation of Umbraco CMS on top of it. Kindly guide.
This issue you are running into here is that - contrary to a standard ASP.Net MVC application - by default Umbraco is going to handle the routing, and so will not be able to resolve your custom controller. If you want to have something standalone, separate to Umbraco but within the same application, you'll need to configure the routing for this yourself.
Something like this - assuming a non-Umbraco controller like this:
public class MyCustomController : Controller
{
public ContentResult Index()
{
return Content("hello");
}
}
You can set up routing for it by adding a class to your application like this:
Creating a custom Controller and View in Umbraco with MVC ?
I m new to Umbraco, have installed Umbacro CMS 7 in my MVC application and doing some test / learning work.
I have created a new controller named Home2, please note I don't have a doc type for Home2. I want to create non Umbraco view/ pages that can work with Umbraco. On running I m getting below error:
Below is my code for Controller and view, please guide what I should do to create custom controllers and views that can work with Umbraco ? Do I need to create document type even for non Umbraco types ?
Controller:
View:
Thanks
Hi Haansi,
Did you read http://our.umbraco.org/documentation/Reference/Mvc/custom-controllers? This was helpfull for me!
Did you create a documenttype Home2?
The umbraco MVC controller logic work with convention over configuration
As for navigation/routing. If you create a document with documenttype Home2 as the root document. It will render the document with the default template if you navigate to localhost:xxx/
Kind regards,
Garret
Thanks Garret,
Is it necessary to create document type ? I mean I don't want to manage this through Umbraco, just want to directly code and mange it. Yet my MVC project has installation of Umbraco CMS on top of it. Kindly guide.
Hi there,
Check out the video below and following the the tutorials:
https://www.youtube.com/watch?v=sDQwu_DzYyc
Cheers,
AL
Hi there,
Check out the video below and following the the tutorials:
https://www.youtube.com/watch?v=sDQwu_DzYyc
Cheers,
AL
This issue you are running into here is that - contrary to a standard ASP.Net MVC application - by default Umbraco is going to handle the routing, and so will not be able to resolve your custom controller. If you want to have something standalone, separate to Umbraco but within the same application, you'll need to configure the routing for this yourself.
Something like this - assuming a non-Umbraco controller like this:
You can set up routing for it by adding a class to your application like this:
Hope that helps
Andy
is working on a reply...