将表值从View传递给Controller MVC

问题描述 投票:0回答:1

我可以将表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 */
} 

如何将表值从视图传递给控制器​​?

使用了JasonData和Ajax调用并能够将表数据发送到控制器。

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

asp.net-mvc razorengine
1个回答
3
投票

您需要生成回发(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" />
}

发布方法

public void PostClick(List<Vendor> model)
{
  /*Some Code */
} 
© www.soinside.com 2019 - 2024. All rights reserved.