HtmlHelper Editor method erroneously render a property of an object in a collection. EditorFor method works correctly.
Steps to reproduce the behavior:
public class MyItemModel
{
public string Name { get; set; }
public int Age { get; set; }
}
public class MyViewModel
{
public List<MyItemModel> Items { get; set; } = new List<MyItemModel>();
}
public IActionResult Index()
{
var model = new MyViewModel();
model.Items.Add(new MyItemModel { Name = "stefano mostarda", Age = 40 });
model.Items.Add(new MyItemModel { Name = "Marco leondini", Age = 50 });
return View(model);
}
@model int
<label>int</label>
<input asp-for="@Model" />
@model string
<label>string</label>
<input asp-for="@Model" />
@model WebApplication5.Controllers.MyViewModel
<p>using EditorFor</p>
@Html.EditorFor(m => m.Items[0].Name)
@Html.EditorFor(m => m.Items[0].Age)
<p>using Editor</p>
@Html.Editor("Items[0].FirstName")
@Html.Editor("Items[0].Age")
Editor and EditorFor should produce the same output.
@sm15455 thanks for contacting us and thanks for providing a repro project.
We'll have a look at it and get back to you.
Thanks for contacting us, @sm15455.
Would you like to send us a PR for this? We'll happily consider it.
@mkArtakMSFT I'd love to do that, but I should investigate the problem (which I think lies in the ViewDataEvaluator class) and, more important, I should download ASP.NET source code, make it build and create the PR. All of these tasks take time. I'll try :D
Most helpful comment
@mkArtakMSFT I'd love to do that, but I should investigate the problem (which I think lies in the ViewDataEvaluator class) and, more important, I should download ASP.NET source code, make it build and create the PR. All of these tasks take time. I'll try :D