In v6 i created a doctype called Master, which contains things such as Title, Meta Description and Meta Title. I have a corresponding controller named MasterController:
public class MasterController : RenderMvcController
{
public override ActionResult Index(Umbraco.Web.Models.RenderModel model)
{
var page = GetPageModel<Page>(model);
return CurrentTemplate(page);
}
public ActionResult Master(Umbraco.Web.Models.RenderModel model)
{
var page = GetPageModel<Page>(model);
return CurrentTemplate(page);
}
public T GetPageModel<T>(RenderModel model) where T : Page, new()
{
var t = new T
{
BrowserTitle = model.Content.GetPropertyValue<string>("browserTitle"),
Title = model.Content.GetPropertyValue<string>("title"),
BodyText = model.Content.GetPropertyValue<string>("bodyText")
};
return t;
}
}
For some reason i canot intercept the route and my custom code in the controller never fires. Im following the documentation and my understanding of the Umbraco conventions the Index action in the MasterController should fire but it does not. So i created another Action method called Master, which also does not fire.
Based on my code example which controller is the request routed too? Any easy ways to debug this?
Also is there anyways we can override the Umbraco convention, which IMO is a bit of a black box.
Can't be very helpful here... other than to say that looks right to me, and I've managed to get something set up the same way as you describe working. The convention is that if a controller matching a document type is found, it'll route to the Index action - unless there's also an action that matches the template name, and then it'll use that. So in your case the Index method should be routed too.
I'll post my code that works... but it's the same as you have as far as I can tell:
using System.Linq;
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
public class VenuesListingController : RenderMvcController
{
public override ActionResult Index(RenderModel model)
{
// Redirect to first node (if exists)
if (model.Content.Children.Any())
{
return Redirect(model.Content.Children.First().Url);
}
return Redirect("/");
}
}
Nope breakpoints not hitting.either in overidden Index action or the Master action. Not sure i understand. If my doctype is named "Master" then what should my controller name be? Please see the code example in my OP
I would try calling your doctype Master and see if you can hit the index action. If then have you got any allowed templates of the doc type? If you have then try:
public class MasterController:RenderMvcController { public override ActionResult yourallowedtemplatename(Umbraco.Web.Models.RenderModel model) { var page = GetPageModel<Page>(model); return CurrentTemplate(page); }
and see if that break point hits :). What do you mean by your OP? :).
How to debug umbraco MVC conventions?
Hi,
In v6 i created a doctype called Master, which contains things such as Title, Meta Description and Meta Title. I have a corresponding controller named MasterController:
A snippet of my master view is:
For some reason i canot intercept the route and my custom code in the controller never fires. Im following the documentation and my understanding of the Umbraco conventions the Index action in the MasterController should fire but it does not. So i created another Action method called Master, which also does not fire.
Based on my code example which controller is the request routed too? Any easy ways to debug this?
Also is there anyways we can override the Umbraco convention, which IMO is a bit of a black box.
Can't be very helpful here... other than to say that looks right to me, and I've managed to get something set up the same way as you describe working. The convention is that if a controller matching a document type is found, it'll route to the Index action - unless there's also an action that matches the template name, and then it'll use that. So in your case the Index method should be routed too.
I'll post my code that works... but it's the same as you have as far as I can tell:
Hi i could be wrong here, but i think you need a controller name of Master to match your doctype? Charlie :).
Hi Charles,
My DocType is named "Master" and the controller is named "MasterController" - This is what the umbraco convention states.
Thanks
That example does feel right. How is it going to know what your doctype name is?
If you are trying to hijack the route. Then your controller need to be the same as your doctype. So:
Are you able to debug, are you hitting any breakpoints?
Nope breakpoints not hitting.either in overidden Index action or the Master action. Not sure i understand. If my doctype is named "Master" then what should my controller name be? Please see the code example in my OP
I would try calling your doctype Master and see if you can hit the index action. If then have you got any allowed templates of the doc type? If you have then try:
and see if that break point hits :). What do you mean by your OP? :).
My original post. The first post in this thread already contains this code.
Ah i see yea i looked at that :) Did my example above work?
is working on a reply...