Controller action method's model parameter is empty when form submit

前端 未结 1 1636
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-26 09:49

I have an action Method ReleasingTheaters in Movie controller, The ReleasingTheaters has two overload one is httpGet which accepts the Movie Id and do stuff and return the Rele

相关标签:
1条回答
  • 2021-01-26 10:23

    You need to change your foreach to a for loop so that the controls are correctly named and can be bound by the DefaultModelBinder

    @for (int i = 0; i < Model.ReleasingTheaters.Count; i++)
    {
      @Html.TextBoxFor(m => m.ReleasingTheaters[i].DateFrom)
      ....
    }
    

    This will generate inputs such as

    <input type="text" name="ReleasingTheaters[0].DateFrom" id="ReleasingTheaters_0__DateFrom" value="?" >
    <input type="text" name="ReleasingTheaters[1].DateFrom" id="ReleasingTheaters_1__DateFrom" value="?" >
    

    Note also that you should not be setting the id attribute with new { id = "DateFrom" } etc. The helpers will render a unique id but you are creating duplicate id's which is invalid html

    0 讨论(0)
提交回复
热议问题