我使用Ajax.beginform以及onbegin
@using (Ajax.BeginForm("NewUser", null, new AjaxOptions { OnSuccess = "UserRoles.onSuccess", OnFailure = "UserRoles.onFailure", HttpMethod = "POST", OnBegin = "return setValues()" }, new { @class = "" }))
{
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.ServiceCentreId)
@Html.HiddenFor(model => model.RoleId)
@Html.HiddenFor(model => model.ProvinceId)
@Html.HiddenFor(model => model.DistrictId)
@Html.HiddenFor(model => model.DivisionId)
@Html.HiddenFor(model => model.TehsilId)
@Html.HiddenFor(model => model.MauzaId)
@Html.HiddenFor(model => model.PatwarCircleId)
@Html.HiddenFor(model => model.QanoonGoiId)
}
function setValues() {
debugger;
var selectedSCrows = $("#gridSC").jqGrid("getGridParam", "selarrrow");
for (var i = 0; i < selectedSCrows.length; i++) {
var rowScData = $("#gridSC").jqGrid('getRowData', selectedSCrows[i]);
$("#ServiceCentreId").val($("#ServiceCentreId").val() + ";" + rowScData.ServiceCentreId);
}
var rolesGridData = UserRoles.getGridData();
if (typeof (rolesGridData) != "undefined") {
for (var j = 0; j < rolesGridData.length; j++) {
$("#RoleId").val($("#RoleId").val() + ";" + rolesGridData[j].RoleId);
$("#ProvinceId").val($("#ProvinceId").val() + ";" + rolesGridData[j].ProvinceId);
$("#DivisionId").val($("#DivisionId").val() + ";" + rolesGridData[j].DivisionId);
$("#DistrictId").val($("#DistrictId").val() + ";" + rolesGridData[j].DistrictId);
$("#TehsilId").val($("#TehsilId").val() + ";" + rolesGridData[j].TehsilId);
$("#QanoonGoiId").val($("#QanoonGoiId").val() + ";" + rolesGridData[j].QanoonGoiId);
$("#PatwarCircleId").val($("#PatwarCircleId").val() + ";" + rolesGridData[j].PatwarCircleId);
$("#MauzaId").val($("#MauzaId").val() + ";" + rolesGridData[j].MauzaId);
}
}
return true;
}
但我没有在控制器中获得更新的值。我调试了java脚本函数setvalues正在调用但我无法在服务器端接收它。
[HttpPost]
public ActionResult NewUser(NewUser newUser)
{
return View(newuser);
}