问题描述
说明
我有一个 ASP.NET MVC 应用程序,用户可以在其中更新表中显示的数据。该表有一列带有输入框,另一列带有复选框,可以在其中编辑和更新数据。
问题
我遇到的问题是当我编辑表格,然后将数据提交给Controller中的方法时,模型参数始终为空。希望下面的代码能更好地描述这个问题。
需要建议
该表可能有超过 1000 行。有没有办法检测已编辑行的更改,并只相应地更新更改的行,而不必更新所有记录?
车辆模型
public string VEHICLE_NAME { get; set; }
public string VEHICLE_MAKE { get; set; }
public string VEHICLE_MODEL { get; set; }
public Nullable<bool> IS_NEW { get; set; }
编辑控制器
[HttpPost]
public ActionResult UpdateTable(List<Vehicle> vehicle) <==vehicle is always null
{
//left out for brevity
}
编辑视图
@using PagedList.Mvc; <==imported asp.net paging namespace for the table
@model PagedList.IPagedList<Vehicle>
@using (Html.BeginForm("UpdateTable","Edit",FormMethod.Post))
{
<table>
<thead>
<tr>
<th>Vehicle name</th>
<th>Vehicle make</th>
<th>Vehicle model</th>
<th>Is New?</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>@Html.displayFor(model => item.VEHICLE_NAME)</td>
<td>@Html.displayFor(model => item.VEHICLE_MAKE)</td>
<td>@Html.TextBoxFor(model => item.VEHICLE_MODEL)</td>
<td><input type="checkBox" name="chk" checked="@(item.IS_NEW)" /></td>
</tr>
}
</tbody>
</table>
//submit button
<input type="submit" value="Submit" />
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)