POST a form array without successful

后端 未结 5 1272
误落风尘
误落风尘 2020-11-21 05:07

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.         


        
5条回答
  •  再見小時候
    2020-11-21 05:35

    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.

提交回复
热议问题