Reputation: 291
After having problems getting a Razor View to render a ViewModel with an embedded IEnumerable
I came across the following post:
View Model IEnumerable<> property is coming back null (not binding) from post method?
I implemented the suggested solution using an editor template but my View was only displaying the first property in the embedded IEnumerable
. I implemented both solutions from the above post but the one with the EditorFor
template is not working for me. My view displays only the ID
property.
Does anyone have any ideas why the soution with the editor template may not be working for my setup? I have implemented it exactly as suggested.
Upvotes: 0
Views: 5244
Reputation: 68
If your view is only displaying the first item then your template is not being picked up in the EditorTemplates folder.
Define your template in the EditorFor extension method like below:
@Html.EditorFor(model => model, "NameofEditorTemplate")
Upvotes: 1
Reputation: 18954
For using Editor Template consider the following tips:
EditorFor
HTML helper to call appropriate template
(when you have specific model to view, It will find the desired
template automatically, otherwise you have to hint the engine,
whether by an argument in EditorFor
or using [UIHint]
attribute
in the model. Look at Extending Editor Templates for ASP.NET MVCstring
, DateTime?
IEnumerable
models for template, consider a very important tip available in EditorFor IEnumerable with TemplateName.Upvotes: 1