Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • John Churchley 272 posts 1257 karma points c-trib
    Dec 22, 2015 @ 12:27
    John Churchley
    0

    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?

    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";
        } 
    
    }
    

    View

    @inherits UmbracoViewPage<JEC.Web.App_Start.MyCustomerViewModel>
    @Model.PropertyIWantForEveryPage;
    
  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    Dec 22, 2015 @ 13:23
    Jeroen Breuer
    100

    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

  • John Churchley 272 posts 1257 karma points c-trib
    Dec 22, 2015 @ 14:08
    John Churchley
    0

    Thanks Jeroen I'll have a look!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies