Copied to clipboard

Flag this post as spam?

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


  • Saied 349 posts 674 karma points
    Jul 09, 2015 @ 20:43
    Saied
    0

    RenderMvcController error?

    I am getting the following error:

    The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel', but this dictionary requires a model item of type 'Product'.

    Here is my model:

    public class Product : RenderModel
    {
        public Product(IPublishedContent content, CultureInfo culture) : base(content, culture)
        {
        }
    
        public Product(IPublishedContent content) : base(content)
        {
        }
    
        public int Id { get; set; }
        public string Make { get; set; }
        public string Model { get; set; }
        public int Year { get; set; }
        public string Engine { get; set; }
    }
    

    Here is my Controller:

    public class ProductController : RenderMvcController
    {
    
        public ActionResult Product(RenderModel model)
        {
            var product = new Product(model.Content, model.CurrentCulture) { Make = "Honda", Model = "Civic" };
    
            return CurrentTemplate(product);
        }
    
    }
    

    Here is my View:

    @inherits UmbracoViewPage<Product>
    @{
            Layout = "Master.cshtml";
        }
        @Model.Make
        <br />
        @Model.Model
    

    I got this to work using a SurfaceController, so I am a bit confused on what the point of a RenderMvcController is?

  • John Churchley 272 posts 1258 karma points c-trib
    Jul 10, 2015 @ 09:03
    John Churchley
    0

    Have you tried adding override to the action result?

    public override ActionResult Product (RenderModel model)

  • Saied 349 posts 674 karma points
    Jul 10, 2015 @ 14:35
    Saied
    0

    John, This is really strange. In my back office, I have a Home and Product Document Type. I also have a matching Template for each(Home and Product). If I create a HomeController:

    public class HomeController : RenderMvcController
    {
    
        public ActionResult Home(RenderModel model)
        {
            var product = new Product(model.Content, model.CurrentCulture) { Make = "Camry" };
    
    
            return CurrentTemplate(product);
        }
    
    }
    

    And then in my View:

    @inherits UmbracoViewPage<Derive.Data.Product>
    
    @{
        Layout = "Master.cshtml";
    }
    
    <h1>@Model.Make</h1>
    

    Everything works fine, but if I do the same exact code with a ProductController with a Product View, I get the error. The only difference between the Home and Product, is that I called my controller ProductController and I called my ActionResult method Product.

  • Saied 349 posts 674 karma points
    Jul 10, 2015 @ 17:51
    Saied
    0

    I figured out the problem, but I am not sure why: The Product page had a DocumentType of Landing Page. Landing Page just allows a Text Page template, so I created a Product Doc Type and Template and allowed Product Templates to be created under the root (Home) node. After doing this, my controller action was hit and everything worked.

  • Jason 17 posts 37 karma points
    Jul 10, 2015 @ 17:58
    Jason
    0

    Dang, this was poised to be the first thread I could actually provide some help with, but you fixed it before I got to it. ;)

    -j

  • Saied 349 posts 674 karma points
    Jul 10, 2015 @ 18:00
    Saied
    0

    Jason, I still don't understand why. I am creating another question.

Please Sign in or register to post replies

Write your reply to:

Draft