Copied to clipboard

Flag this post as spam?

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


  • Paul Sørensen 304 posts 650 karma points
    Mar 21, 2015 @ 23:45
    Paul Sørensen
    0

    The model item passed into the dictionary is of type 'Umbraco.Web.Models.RenderModel'

    Hi

    I have searched and seen that many have this problem, but I haven't found a solution to my problem. It's v7.2.2

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

    The Document is named ResultMatch

    My controller is
    ResultMatchSurfaceController.cs:

    public class ResultMatchSurfaceController : SurfaceController
    {
    public ActionResult Index()
    {
    Log.Info("ResultMatch:Index called");
    var resModel = new ResultMatchViewModel();
    return View("ResultMatch", resModel);
    }
    public ActionResult ResultMatch()
    {
    Log.Info("ResultMatch:ResultMatch called");
    var resModel = new ResultMatchViewModel();
    return View("ResultMatch", resModel);
    }
    }

    The model is
    ResultMatchViewModel.cs:

    public class ResultMatchViewModel : RenderModel
    {
    ...
    }

    and the view is:
    ResultMatch.cshtml:

    @using MySite.Models
    @inherits Umbraco.Web.Mvc.UmbracoViewPage
    @{
        Layout = "ResultLayout.cshtml";
    } ....

    Neither of the 2 methods get hit. Any ideas?

    /Paul S

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Mar 22, 2015 @ 17:12
    Matt Brailsford
    0

    Hi Paul,

    I think I see your problem. If I'm understanding correctly, you are attempting to hijack a route so that you can pass down a custom view model correct?

    The issue is, you need to implement the interface IRenderMvcController in order to tell Umbraco that your controller should be used for hijacking (I think you may be confused about the difference between surface controllers and route hijacking controllers).

    If you change your ResultMatchSurfaceController.cs file to be:

    public class ResultMatchSurfaceController : SurfaceController, IRenderMvcController 
    {
        public ActionResult Index(Umbraco.Web.Models.RenderModel model)
        {
            Log.Info("ResultMatch:Index called");
            var resModel = new ResultMatchViewModel();
            return View("ResultMatch", resModel);
        }
    
        public ActionResult ResultMatch(Umbraco.Web.Models.RenderModel model)
        {
            Log.Info("ResultMatch:ResultMatch called");
            var resModel = new ResultMatchViewModel();
            return View("ResultMatch", resModel);
        }
    }
    

    I think they should start working.

    In terms of understanding the difference between surface controller and route hijacking controllers, I'd suggest reading the following

    https://our.umbraco.org/Documentation/Reference/Mvc/surface-controllers
    https://our.umbraco.org/documentation/Reference/Mvc/custom-controllers

    TLDR; Surface controllers are generally for child actions that need to interact with the current page, such as form handlers, where as route hijacking controllers are for hijacking and altering an entire page request.

    Hope this helps.

    Matt

  • Paul Sørensen 304 posts 650 karma points
    Mar 22, 2015 @ 22:00
    Paul Sørensen
    0

    Hi Matt

    You're right - I am a bit confused but I understand the change and thanks for that.

    Unfortunately is does not make a difference and still neither of the methods get hit. There is nothing in the log that could reveal the solution.

    /Paul S

  • Matt Brailsford 4124 posts 22215 karma points MVP 9x c-trib
    Mar 22, 2015 @ 22:13
    Matt Brailsford
    0

    Ahh, sorry, my bad. I don't think you can mix surface controllers with route hijacking controllers (which is what my previous example was doing) as the route hijacker will look for controller matching DocTypeAliasController. Try changing your controller class to the following, I think this one should work.

    public class ResultMatchController : Umbraco.Web.Mvc.RenderMvcController
    {
        public ActionResult Index(Umbraco.Web.Models.RenderModel model)
        {
            Log.Info("ResultMatch:Index called");
            var resModel = new ResultMatchViewModel();
            return View("ResultMatch", resModel);
        }
    
        public ActionResult ResultMatch(Umbraco.Web.Models.RenderModel model)
        {
            Log.Info("ResultMatch:ResultMatch called");
            var resModel = new ResultMatchViewModel();
            return View("ResultMatch", resModel);
        }
    }
    

    Matt

  • Paul Sørensen 304 posts 650 karma points
    Mar 22, 2015 @ 23:03
    Paul Sørensen
    0

    Hi Matt

    This works but the reason why I choose a SurfaceController is because I have a drop down list where I can select the key for the details displayed.
    I believe a SelectionChanged event should trigger a POST back to the controller and how I read the documentation I should use a SurfaceController. I have been searching for an example but without luck.

    /Paul S 

  • Gary 7 posts 71 karma points
    Mar 23, 2015 @ 06:06
    Gary
    0

    Hi Paul & Matt

    I am new to Umbraco and I have some similar problems.

    Can I ask how you can create a ResultMatchViewModel without passing any IPublishedContent in if it is inherits from RenderModel?

    Gary

  • Tajamal 87 posts 175 karma points
    Jan 06, 2016 @ 14:11
    Tajamal
    0

    Hi Paul & Matt

    I am also new to umbraco and been looking for something similar without any luck.

    Goal: To post and return results for the page with custom model.

    I created an Umbraco page and made my custom controller, modelview.

    My code below:

    View

    @using ClientDependency.Core.Mvc
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }
    
    
    
    @{
        Html.RenderAction("Index", "SearchPage");
    }
    

    Controller: As you can see, i cant return partialview, as it wont return my actual page, instead have to use RedirectToCurrentUmbracoPage() and store my model in a session.

    public class SearchPageController : SurfaceController
        {
            [HttpGet]
            public ActionResult Index(string query, int? page = 1)
            {
    
                return PartialView("~/Views/Search/Index.cshtml", GetSearch(query, page));
            }
    
    
            [HttpPost]
            public ActionResult Result(string query, int? page = 1)
            {
                Session["mySearch"] = GetSearch(query, page);
                return RedirectToCurrentUmbracoPage();
            }
    
            private static SearchResultView GetSearch(string query, int? page = 1)
            {//some search logic}
    

    Partial view

    @using MyProject.Models
    @using PagedList.Mvc
    @model SearchResultView
    @{
        var mod = Session["mySearch"] != null ? (SearchResultView)Session["mySearch"] : Model;
    }
    
  • Tajamal 87 posts 175 karma points
    Jan 06, 2016 @ 15:35
    Tajamal
    0

    I went back and derived my model from RenderModel and I ended up making two different views. One for get and one for post. This also solved my layout and page navigation problem that I struggled with.

Please Sign in or register to post replies

Write your reply to:

Draft