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 { ... }
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
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.
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);
}
}
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.
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.
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.
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:
The model is
ResultMatchViewModel.cs:
and the view is:
ResultMatch.cshtml:
Neither of the 2 methods get hit. Any ideas?
/Paul S
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:
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
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
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.
Matt
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
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
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
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.
Partial view
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.
is working on a reply...