I\'m developing an ASP.NET MVC 5 web with C# and .NET Framework 4.5.1.
I have this form
in a cshtml
file:
@model MyProduct.
Following the principle of DRY, you can create one EditorTemplate for that purpose. Steps:
1- In Views > Shared > Create new folder named (EditorTemplates)
2- Create a view inside your newly created EditorTemplates folder , the view's model should be BatchProductViewModel according to the OP example. Place your code inside the Editor view. No loop or index is required.
An EditorTemplate will act similar to a PartialView for every child entity but in a more generic way.
3- In your parent entity's view, call your Editor : @Html.EditorFor(m => m.BatchProducts)
Not only this provides a more organized views, but also let's you re-use the same editor in other views as well.