For each pages on our site I'm looking to have a custom Model. I was hoping there was a way changing the default-controller and passing a custom model inherited from RenderModel on a Default Controller.
Can anyone point me in the right direction?
namespace JEC.Web.App_Start
{
public class ApplicationEventHandler : IApplicationEventHandler
{
public void OnApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
DefaultRenderMvcControllerResolver.Current.SetDefaultControllerType(typeof(MyCustomUmbracoController));
}
}
}
namespace JEC.Web.App_Start
{
class CustomBaseUmbracoController : Umbraco.Web.Mvc.RenderMvcController
{
public override ActionResult Index(RenderModel model)
{
var viewModel = new MyCustomerViewModel(model.Content, model.CurrentCulture);
//Do some stuff here, then return the base method
return View(viewModel);
}
}
}
namespace JEC.Web.App_Start
{
class MyCustomerViewModel : RenderModel
{
public MyCustomerViewModel(IPublishedContent content, CultureInfo culture)
: base(content, culture)
{
}
public string PropertyIWantForEveryPage { get{
return "MyValue";
}
}
Using a Custom Default Controller
For each pages on our site I'm looking to have a custom Model. I was hoping there was a way changing the default-controller and passing a custom model inherited from RenderModel on a Default Controller.
Can anyone point me in the right direction?
View
Hello,
I made some examples in the Hybrid Framework. I haven't updated in a while, but the example should still work: https://our.umbraco.org/projects/developer-tools/hybrid-framework-for-umbraco-v7
Jeroen
Thanks Jeroen I'll have a look!
is working on a reply...