let your base controller inherit from RenderMvcController and add a method like this:
protected T CreateModel<T>() where T : RenderModel, new()
{
var viewModel = new T()
{
// you can set properties here if you are inheriting from other interfaces
};
//add an umbraco data token so the umbraco view engine executes
RouteData.DataTokens["umbraco"] = viewModel;
return viewModel;
}
You can also add this to the base controller to have the Index action required in all controllers:
public abstract override ActionResult Index(RenderModel model);
In your controller inheriting from the base controller you will have something like this:
public override ActionResult Index(RenderModel model)
{
// do lookups ...
var vm = CreateModel<MyViewModel>();
// set properties for your viewmodel
return CurrentTemplate(vm);
}
Custom Route missing from route values
Ive set up a custom route and initialized it on ApplicationStarted as below.
When I open the application if I go straight to the URL I want routed I get the following error when the following code gets called.
which comes from a call to Umbraco.Web.Mvc.SurfaceController.get_CurrentPage() I think.
The weird thing is, If I visit a standard page like the home page first and then go to my custom route, all works as expected..!
Having spent most of the day on this one, if anyone has any ideas I'd love to hear them :)
Thanks
Hi Neil,
does your controller inherits from RenderMvcController?
Hey David,
We have the controller inheriting from a page base controller which in turn inherits from SurfaceController, IRenderMvcController
Thanks
Hi Neil,
let your base controller inherit from RenderMvcController and add a method like this:
You can also add this to the base controller to have the Index action required in all controllers:
In your controller inheriting from the base controller you will have something like this:
Hi Neil,
How have you solved your problem?
Thank you for your sharing
Kind Regards
is working on a reply...