Umb 6 Custom Model - The model item passed into the dictionary is of type.... requires Umbraco.Web.Models.RenderModel
Hey y'all,
I'm developing locally with the UmbracoCms.6.0.3 release.
I am hoping someone can point me in the right direction. I have had a look around Our and googled about it too, but just can't seem to join the dots. I can set up a custom model, but having a template use that model AND have a layout to sit it fails. :-/
I have a template to display the item which is used by an item in the cms - simplistiy they are named the same thing so http://dev.website.local/custom is the name of the page in the cms and "custom" is the name of the template - and by debugging I know this page is being hit.
@inherits Umbraco.Web.Mvc.UmbracoViewPage<SiteNamespace.UmbracoMVC.Models.CustomModel>
@{
Layout = "_layout.cshtml";
}
<div>webpage with using the custom model</div>
<div>@Model.CustomItem</div>
I have a layout page (_layout.cshtml) which the template should be using.
public class CustomController : Umbraco.Web.Mvc.RenderMvcController
{
public override ActionResult Index(RenderModel model)
{
//Do some stuff here, then return the base method
//return base.Index(model);
var customModel = new CustomModel()
{
things = ThingService.ReadAll(),
};
return CurrentTemplate(customModel);
}
}
But this gives me
The model item passed into the dictionary is of type
'SiteNamespace.UmbracoMVC.Models.CustomModel', but this
dictionary requires a model item of type
'Umbraco.Web.Models.RenderModel'.
If I change the template to not reference the shared _layout, it has no issues.
@inherits Umbraco.Web.Mvc.UmbracoViewPage<SiteNamespace.UmbracoMVC.Models.CustomModel>
@{
Layout = null;
}
<div>webpage with using the custom model</div>
<div>@Model.CustomItem</div>
So, any ideas what I am missing here? Probably something obvious.
If we are not able (nor want) to change our custom controllers to inherit from RenderMvcController and to change our custom models to inherit from RenderModel, ... is there any other way to do this?
If not, is this a technical limitation of how Umbraco.Web.Mvc.UmbracoViewPage<T> works? Or is it more fundamental. Without understanding how this is built (obviously), I wonder why it can't figure out on its own the current context and require me to modify existing MVC apps just so I can get access to some Umbraco helpers.
My situation is that I have a website that I want to be 90% Umbraco, with lovely things like a master layout and macros/partials to generate navigation bars, sidebars, and a footer, etc. And then, I have a custom MVC app that I simply want to be able to generate views that use this same master layout which is able to generate the same navigation bars, sidebars, and footer, etc. However, it seems I have to completely revamp my existing MVC app's controllers and models or else the views won't work? I don't understand why this shouldn't be possible.
I'm also having the same problem, but something a little different with me is that, I am hijacking the route because I need to get data from a custom table. Hence the UmbracoContext is always null and it breaks when I try to initialize my custom model.
Umb 6 Custom Model - The model item passed into the dictionary is of type.... requires Umbraco.Web.Models.RenderModel
Hey y'all,
I'm developing locally with the UmbracoCms.6.0.3 release.
I am hoping someone can point me in the right direction. I have had a look around Our and googled about it too, but just can't seem to join the dots. I can set up a custom model, but having a template use that model AND have a layout to sit it fails. :-/
I've followed http://our.umbraco.org/Documentation/Reference/Mvc/custom-controllers but I must be missing something.. I'll replace the name used for the template/controller/model, with Custom
I have a template to display the item which is used by an item in the cms - simplistiy they are named the same thing so http://dev.website.local/custom is the name of the page in the cms and "custom" is the name of the template - and by debugging I know this page is being hit.
I have a layout page (_layout.cshtml) which the template should be using.
A custom controler
But this gives me
The model item passed into the dictionary is of type 'SiteNamespace.UmbracoMVC.Models.CustomModel', but this dictionary requires a model item of type 'Umbraco.Web.Models.RenderModel'.
If I change the template to not reference the shared _layout, it has no issues.
So, any ideas what I am missing here? Probably something obvious.
Thanks!
have you tried using it with another layout to see what the result is. maybe you have a duff reference to something???
Hey Rav! You know what, I didn't think I had anything complex or interesting going on in the _layout ... so hadn't tried that.
No difference :-/
Thanks though. :)
Hi Peter,
Derive your CustomModel from RenderModel and all will be solved... Example:
Cheers,
/Dirk
Works perfectly thanks.
See this thread: http://our.umbraco.org/forum/templating/templates-and-document-types/38311-Using-RenderMvcController which looks to be the same issue and has various solutions.
You'll need to make sure your layout/view models inherit from each other (and have @model dynamic on your base layout if appropriate)
Stephen
Thanks guys!
Makes sense Dirk, you deserve more than a High Five.... a grade A man-hug.
Ta!
If we are not able (nor want) to change our custom controllers to inherit from RenderMvcController and to change our custom models to inherit from RenderModel, ... is there any other way to do this?
If not, is this a technical limitation of how Umbraco.Web.Mvc.UmbracoViewPage<T> works? Or is it more fundamental. Without understanding how this is built (obviously), I wonder why it can't figure out on its own the current context and require me to modify existing MVC apps just so I can get access to some Umbraco helpers.
My situation is that I have a website that I want to be 90% Umbraco, with lovely things like a master layout and macros/partials to generate navigation bars, sidebars, and a footer, etc. And then, I have a custom MVC app that I simply want to be able to generate views that use this same master layout which is able to generate the same navigation bars, sidebars, and footer, etc. However, it seems I have to completely revamp my existing MVC app's controllers and models or else the views won't work? I don't understand why this shouldn't be possible.
Thank you for any help or guidance!
Thanks Dirk
I just inherited from RenderModel, thanks very much Dirk!!!
Hi guys,
I'm also having the same problem, but something a little different with me is that, I am hijacking the route because I need to get data from a custom table. Hence the UmbracoContext is always null and it breaks when I try to initialize my custom model.
Please help.
is working on a reply...