var items = Model.MyNestedContentProperty as IEnumerable<PublishedElementModel>;
@Html.Partial("inPageNav", items);
throws
Cannot bind source type Umbraco.Web.PublishedModels.NestedContent to
model type
System.Collections.Generic.IEnumerable`1[[Umbraco.Core.Models.PublishedContent.PublishedElementModel,
Umbraco.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null]].
Defining the view instead as
@model IEnumerable<PublishedElementModel>
throws
The model item passed into the dictionary is of type
'Umbraco.Web.PublishedModels.NestedContent', but this dictionary
requires a model item of type
'System.Collections.Generic.IEnumerable`1[Umbraco.Core.Models.PublishedContent.PublishedElementModel]'.
I know that I don't really understand how it is supposed to work. I am grateful for some hints in the right direction. Thank you!
And from your code, I can see that the error is throwing because of Passing Model and binding models are different.
Cannot bind source type Umbraco.Web.PublishedModels.NestedContent to model type System.Collections.Generic.IEnumerable1[[Umbraco.Core.Models.PublishedContent.PublishedElementModel]].
Please use the same Model for both passing and binding
IF the above is not working, please use the dynamic way
Simple way to pass parameter to partial view with Umbraco 8
What's the simplest way to pass a parameter to a partial view in Umbraco 8 ? I am (still) inexperienced with MVC and I am grateful for some insight.
I want to pass a
IEnumerable<PublishedElementModel>
parameter (the value of a a nested content property) to a partial view.Using Macro Partials doesn't work out of the box.
IEnumerable<PublishedElementModel>
is not available as a macro parameter type.This is my view definition:
the model type
NestedContent
has a nested content propertyMyNestedContentProperty
.With the partial view
inPageNav
defined ascalling the partial like
throws
Defining the view instead as
throws
I know that I don't really understand how it is supposed to work. I am grateful for some hints in the right direction. Thank you!
Hey Mikael, You can simply pass the Model to a Partial View
1)
2)
Please see here for more info
https://our.umbraco.com/Documentation/Reference/Templating/Mvc/partial-views
https://www.jondjones.com/learn-umbraco-cms/umbraco-7-tutorials/umbraco-and-mvc/how-to-use-mvc-partials-in-umbraco/
And from your code, I can see that the error is throwing because of Passing Model and binding models are different.
Cannot bind source type Umbraco.Web.PublishedModels.NestedContent to model type System.Collections.Generic.IEnumerable1[[Umbraco.Core.Models.PublishedContent.PublishedElementModel]].
Please use the same Model for both passing and binding
IF the above is not working, please use the dynamic way
here
Danesh,
thank you for your answer. Now I get it :-)
I was thinking too complicated. I got it working in no time thanks to your advice.
Very cool. Mikael
You can also pass parameters in a ViewDataDictionary like this:
Here I'm passing the Model, and 2 parameters into the PartialView.
In the PartialView you can then do like this to access the parameters:
is working on a reply...
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.