Copied to clipboard

Flag this post as spam?

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


  • Pommer3 2 posts 33 karma points
    Jun 11, 2020 @ 11:46
    Pommer3
    0

    Problem with code in Custom controller not beging executed (Route hijacking)

    I have a problem where the code in my custom controller does not get executed. I think i have followed the guide correctly found here: https://our.umbraco.com/documentation/reference/routing/custom-controllers But the result does not reflect it as it does not work.

    Controller:

    public class FrontPageController : RenderMvcController
    {
        public override ActionResult Index(ContentModel model)
        {
            //InitializeBaseModel(model);
            //var blogService = new BlogService();
            var frontPageModel = new FrontPageModel(model.Content);
            frontPageModel.Headline = frontPageModel.Value<string>("headline");
    
    
            return CurrentTemplate(model);
        }
    
    
    }
    

    The alias for the document type is FrontPage

    Model:

    public class FrontPageModel : BaseModel
    {
    
        public string Headline { get; set; }
    
    
        public FrontPageModel(IPublishedContent content) : base(content)
        {
        }
    }
    

    Template named FrontPageTemplate starts with the following and has a mastertemplate that does not have any model, but just a @RenderBody:

    @inherits UmbracoViewPage

    I get this error:

    enter image description here

    Any help would be very much appreciated as i have been struggling for several long hours without any improvement and google has not been my friend!

  • Steve Morgan 1278 posts 4216 karma points c-trib
    Jun 11, 2020 @ 13:38
    Steve Morgan
    100

    Change the line in the Controller

     return CurrentTemplate(model);
    

    To

     return CurrentTemplate(frontPageModel);
    

    Also check you've changed the view template top line something like:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<MyNamespace.Models.FrontPageModel>
    
  • Pommer3 2 posts 33 karma points
    Jun 11, 2020 @ 14:38
    Pommer3
    1

    Thank you very much! I had missed the detail with the model :)

  • 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