Using traditional MVC controller structure and routing in Umbraco
In traditional MVC you can set up a controller as follows
public class ProductsController {
public ActionResult Index(){
// general products stuff.
}
public ActionResult Product(int id){
// product specific stuff.
}
}
With this I can have the routes
/products
/products/product/1
Great! I get to reuse a controller as nature intended. Yay MVC!
With Umbraco, as far as I have ever been able to ascertain, to achieve those routes, you have to follow this pattern:
public class ProductsController : RenderMvcController {
public override ActionResult Index(){
// general products stuff.
}
}
public class ProductController : RenderMvcController {
public ActionResult Product(int id){
// product specific stuff.
}
}
I hate having to create a new controller every time I want sub pages under a route.
Question is... Have I missed something? Have I been slowly driving myself mad doing it incorrectly or is this simply how Umbraco works?
I could do whacky things using IContentFinder or by defining additional routes using the new technique here but that feels and is hacky.
If this is the way things are then why is it laid out that way?
That's using the IContentFinder plus a whole lot of hackery which has been superseeded by using the combination of MapUmbracoRoute and UmbracoVirtualNodeRouteHandler which is still a hack in my opinion.
It's pretty screwy the way it works just now. Doctypes in the back office should have some sort of rootprovider option which would allow routing to follow the traditional format.
Using traditional MVC controller structure and routing in Umbraco
In traditional MVC you can set up a controller as follows
With this I can have the routes
Great! I get to reuse a controller as nature intended. Yay MVC!
With Umbraco, as far as I have ever been able to ascertain, to achieve those routes, you have to follow this pattern:
I hate having to create a new controller every time I want sub pages under a route.
Question is... Have I missed something? Have I been slowly driving myself mad doing it incorrectly or is this simply how Umbraco works?
I could do whacky things using
IContentFinder
or by defining additional routes using the new technique here but that feels and is hacky.If this is the way things are then why is it laid out that way?
Hi James,
Maybe this article by warren can help you out : http://creativewebspecialist.co.uk/2013/12/03/using-umbraco-pipeline-for-member-profile-urls/
Dave
Hi Dave,
No absolutely not I'm afraid.
That's using the
IContentFinder
plus a whole lot of hackery which has been superseeded by using the combination ofMapUmbracoRoute
andUmbracoVirtualNodeRouteHandler
which is still a hack in my opinion.It's pretty screwy the way it works just now. Doctypes in the back office should have some sort of rootprovider option which would allow routing to follow the traditional format.
Cheers
James
is working on a reply...