I have a partial view which is being used on pages with multiple document types. I'm looking for a way to use Models Builder syntax inside this partial view, perhaps by somehow passing the model type into it.
I know how to pass the model itself into the Partial View, but on the Partial View end, the model is always of type IPublishedContent, rather than the current doctype's Models Builder type.
Is there some way to do this, or do I have to use the .Value() syntax to access page data if the document type varies?
That's the thing, I am not passing the same type of model every time. Is there a way to pass the type of the model into the partial view, so that the inherited model type can vary?
Not that I know of. In that scenario, that is why it defaults back to IPublishedContent as all the models are of that type.
Do they have common properties between the models, and if so were those properties added via a composition. If they were then you could have a model type which is the interface created by the composition.
For example,
Composition type - SEO - Has PageTitle and MetaDescription properties.
All doc types have SEO as part of their composition, so the models all inherit from ISeo
Thanks! I tried to do something similar by using the type of the doctypes' parent, which didn't work, but doing it with compositions makes sense. I'll give that a try!
No problem, the other option you have is create your own model class and specify that as the models type. You'd have to populate the model before each call though :-)
Pass Models Builder model to a partial view?
I have a partial view which is being used on pages with multiple document types. I'm looking for a way to use Models Builder syntax inside this partial view, perhaps by somehow passing the model type into it.
I know how to pass the model itself into the Partial View, but on the Partial View end, the model is always of type IPublishedContent, rather than the current doctype's Models Builder type.
Is there some way to do this, or do I have to use the .Value() syntax to access page data if the document type varies?
If you are always passing the same type of model every time then you can change the inherits statement from:
to
This would make your view expect the model type you've specified :-)
Nik
That's the thing, I am not passing the same type of model every time. Is there a way to pass the type of the model into the partial view, so that the inherited model type can vary?
Not that I know of. In that scenario, that is why it defaults back to IPublishedContent as all the models are of that type.
Do they have common properties between the models, and if so were those properties added via a composition. If they were then you could have a model type which is the interface created by the composition.
For example,
Composition type - SEO - Has PageTitle and MetaDescription properties.
All doc types have SEO as part of their composition, so the models all inherit from ISeo
In this situation you could do
And then things like
would potentially exist.
Thanks! I tried to do something similar by using the type of the doctypes' parent, which didn't work, but doing it with compositions makes sense. I'll give that a try!
No problem, the other option you have is create your own model class and specify that as the models type. You'd have to populate the model before each call though :-)
Nik
is working on a reply...