What is the best approach to sharing a partial view, across different view files?
For instance, i have a section on all pages, that are the same; a small section with related links, that simply checks if "Model.RelatedLinks" is populated, and if it is, displays them.
My Doc Types are built with compositions, so the related links section, is shared across many doc types.
But, when i try to use it, i get an error like; Cannot bind source content type Umbraco.Web.PublishedContentModels.DocType1 to model type Umbraco.Web.PublishedContentModels.DocType2.
I the partial view for my related links, i have: @inherits UmbracoViewPage<DocType1>.
So this partial view, only works, when i use it, on a view of the type @inherits UmbracoViewPage<DocType1>
What is the best approach forward, so i do not have to have the same snippet of code on each view, but can gather it into views?
when you use compositions, the doctypes are used as actual interfaces to your doc types. So I would suggest that you use that "composition interface" in your partial view. Then you can use every doc type that uses the composition.
Share partial views across layouts?
What is the best approach to sharing a partial view, across different view files?
For instance, i have a section on all pages, that are the same; a small section with related links, that simply checks if "Model.RelatedLinks" is populated, and if it is, displays them.
My Doc Types are built with compositions, so the related links section, is shared across many doc types.
But, when i try to use it, i get an error like;
Cannot bind source content type Umbraco.Web.PublishedContentModels.DocType1 to model type Umbraco.Web.PublishedContentModels.DocType2.
I the partial view for my related links, i have:
@inherits UmbracoViewPage<DocType1>
. So this partial view, only works, when i use it, on a view of the type@inherits UmbracoViewPage<DocType1>
What is the best approach forward, so i do not have to have the same snippet of code on each view, but can gather it into views?
Hi Dinovo,
when you use compositions, the doctypes are used as actual interfaces to your doc types. So I would suggest that you use that "composition interface" in your partial view. Then you can use every doc type that uses the composition.
Hi Dinovo,
Like David all ready mentioned you should use the composition interface or doctype on your partial view then.
Some thing like this
or
Dave
is working on a reply...