将 Table 值从视图传递到控制器 MVC

Pass Table Value from View to Controller MVC

我可以将 table td 值传递给控制器​​吗?

强类型视图:

@using (Html.BeginForm("PostClick", "Vendor", FormMethod.Post)) {
<table class="tblData">
  <tr>
    <th>
      @Html.DisplayNameFor(model => model.First().SubmittedDate)
    </th>
    <th>
      @Html.DisplayNameFor(model => model.First().StartDate)
    </th>
  </tr>

  <tr>
    <td>
      @Html.DisplayFor(modelItem => item.SubmittedDate)
    </td>
    <td>
      @Html.DisplayFor(modelItem => item.StartDate)
    </td>
   </tr>
 </table>
 <input type="submit" value="submit" />
    }

控制器代码:

public void PostClick(FormCollection collection)
{
   /*Some Code */
} 

如何将 table 值从视图传递到控制器?

已使用 JasonData & Ajax 调用并能够将 table 数据发送到控制器。

想知道任何其他方法都可以完成,因为 FormCollection 数据无法找到 table 值

您需要生成 post 返回的控件(inputtextareaselect)并在 for 循环中生成这些控件(或使用自定义 EditorTemplate 类型 Vendor)

查看

@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方法

public void PostClick(List<Vendor> model)
{
  /*Some Code */
}