Pass Table Value from View to Controller MVC

天大地大妈咪最大 提交于 2019-12-06 15:57:30

Your need to generate controls that post back (input, textarea or select) and generate those controls in a for loop (or use a custom EditorTemplate for type Vendor)

View

@model List<Vendor>
@using (Html.BeginForm())
{
  <table class="tblData">
    <thead>
      ....
    </thead>
    <tbody>
      for(int i = 0; i < Model.Count; i++)
      {
        <tr>
          <td>@Html.TextBoxFor(m => m[i].SubmittedDate)</td>
          <td>@Html.TextBoxFor(m => m[i].StartDate)</td>
        </tr>
      }
    </tbody>
  </table>
  <input type="submit" value="submit" />
}

Post method

public void PostClick(List<Vendor> model)
{
  /*Some Code */
} 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!