Closed skttl closed 4 years ago
You can have partial views declared with the model you want like @model Feature
and pass in Model.Content to render your Partial then there is no explicit casting since that is done implicitly by the partial view
I know, but if you need both the settings and the content in your partial view, then you can't. I would like a way to have Model.Content and Model.Settings in a specific model.
Can you use a tuple? like passing in (Model.Content, Model.Settings)
and then have @model (Feature,FeatureSettings)
?
Another option is to create a custom UmbracoViewPage that allows this.
This is was undocumented feature of ditto . https://github.com/umco/umbraco-ditto/blob/develop/src/Our.Umbraco.Ditto/Web/Mvc/DittoView.cs
So instead of doing @inherits UmbracoViewPage<MyModel>
you would do @inherits UmbracoViewPage<DittoView>
So you could create a UmbracoBlockViewPage which exposes the content and the settings.
Dave
@Shazwazza nope, getting
Cannot bind source type System.ValueTuple`2[[Umbraco.Core.Models.PublishedContent.IPublishedElement, Umbraco.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null],[Umbraco.Core.Models.PublishedContent.IPublishedElement, Umbraco.Core, Version=8.0.0.0, Culture=neutral, PublicKeyToken=null]] to model type System.ValueTuple`2[[Umbraco.Web.PublishedModels.Feature, 87rc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Umbraco.Web.PublishedModels.Feature, 87rc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].
when doing
@foreach (var block in Model.Blocks)
{
@Html.Partial("BlockList/" + block.Content.ContentType.Alias, (block.Content, block.Settings))
}
Partial view has
@inherits UmbracoViewPage<(Feature Content, Feature Settings)>
Something like UmbracoBlockViewPage<T1,T2> would work too :)
I guess then Model would be T1, and Settings would be T2
Yeah was afraid of that, i'm sure there's a way to tell razor to know about tuples in it's web.config but I've never tried. Else you can use the non value tuple like Tuple<Content, Settings>
but that's a bit uglier. Anyways, just providing info :)
Fixed in #8841
In the first version of the block list, if you need to use ModelsBuilder models for your views, you need to write a bit of code in your view, like:
It would be much nicer, if you could handle the models in the
@inherits
statement, likeThis would result in
Model.Content
beingFeature
, andModel.Settings
beingFeatureSettings