Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I'm using the out of the box Model Builder that comes with Umbraco I have enabled it in the web.config file like so:
<add key="Umbraco.ModelsBuilder.Enable" value="true" />
<add key="Umbraco.ModelsBuilder.ModelsMode" value="Dll" />
Umbraco Is successfully creating the Model classes and I can see them in my visual studio project.
In my controller, I'm using one of the generated models and I am getting all the values. For example:
public ActionResult Index(Home model)
//model is now a strongly typed (Home Document type)
var test = model.Descendants("myContentTypeAlias")
In the example above the variable test is a collection of IPublishedContent - My question is how can I make that list strongly typed based on the models that Umbraco has created.
Thanks in advance.
You can add .OfType<MyContentAlias>() to model.Descendants("myContentTypeAlias") to get your collection in the right model.
Thank you! - Exactly what I needed.... do you know where this is in the documentation, without your answer I would have struggled to find that.
I got just a little issue with this, my query returns me 0 result.
Is there anyway to specify a document type as a Custom Model or I am missing something?
public class ProductModel : ContentModel
public ProductModel(IPublishedContent content) : base(content)
var allProducts = Model.Descendants("product").OfType<ProductModel>();
foreach (ProductModel product in allProducts)
Is your ProductModel a model generated by ModelsBuilder? It has to be, else you can't cast it that way.
Yes it is!
Now I got the error "Cannot bind ProductModel to ContentModel"
Ok got it. I had to pass my IPublishedContent as an agrument -_- hehe
You could probably also try the following:
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted