0
我有表像下面的.cshtml如何從瀏覽列表傳遞數據的控制器
@using (Html.BeginForm("About","Home"))
{
<div id="Test">
<table id="DeptIds">
@for (int i = 0; i <= @Model.Count()-1;i++)
{
<tr>
<td>
@Html.TextBoxFor(x => x[i].DeptId)
</td>
<td>
@Html.TextBoxFor(x => x[i].DeptName)
</td>
</tr>
}
</table>
<input type="button" value="HitMe" onclick="Save()" />
</div>
}
<script>
function Save()
{
$.ajax({
type: 'POST',
url: '@Url.Action("About")',
data: $("#Test").serialize(),
success: function (data) {
alert(data);
$('.tampil_vr').text(data);
}
});
}
</script>
保存功能將做AJAX方法和序列的所有數據,並傳遞給控制器。
控制器代碼:
[HttpPost]
public ActionResult About(List<Dept> obj)
{
ViewBag.Message = "Your app description page.";
return View();
}
當我執行obj爲null,但在OBJ如果我更改類型=「提交」我得到的名單數據。那麼如何在ajax調用中填充obj。