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
    Sep 01, 2015 @ 20:09
    Saied
    0

    RenderModel expected error?

    I have a partial view called ProductFilter.cshtml. It is in a view Products.cshtml and defined like so:

    @{
        Html.RenderPartial("ProductFilter",new ProductFilterModel());
    }
    

    The ProductFilterModel looks like this:

    public class ProductFilterModel
    {
        public string Make { get; set; }
        public string Model { get; set; }
        public string Year { get; set; }
        public string Engine { get; set; }
    }
    

    I have a controller ProductFilterController that looks like this:

    public class ProductFilterController : SurfaceController
    {
        [HttpPost]
        public ActionResult SearchResults(
                       ProductFilterModel productFilterModel)
        {
            return View(productFilterModel);
        }
    }
    

    When I go to the Products page and click on search, I get the error that it excepts a RenderModel, but I am passing it a ProductFilterModel

    My SearchResults.cshtml looks like this:

    @model ProductFilterModel
    
    @{
        Layout = "../Master.cshtml";
    }
    
    @Model.Engine
    

    If I remove the Master, everything works, but I lose all styling.

  • Saied 349 posts 674 karma points
    Sep 02, 2015 @ 02:42
    Saied
    100

    OK, I figured it out or at least it is one way of solving it. I ended up inheriting from RenderModel, but this isn't enough because once I inherit from RenderModel, it doesn't have any parameterless constructors, so I had to add the following line:

    public ProductFilterModel():
    this(new UmbracoHelper(UmbracoContext.Current).
    TypedContent((UmbracoContext.Current.PageId)))
     {
    
     }
    
  • 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