serializeEditData后 Controller中就取不到参数了,一直为null
后来采用扩展ModelBinder方法
很奇怪也绑定失败,后来发现controllerContext.HttpContext.Request.Form[bindingContext.ModelName] 为空。赶进度,没办法只能用controllerContext.HttpContext.Request.Form[0],以后再研究吧
网页
var editSettings = {
closeAfterEdit: true,
reloadAfterSubmit: true,
closeOnEscape: true,
datatype: 'json',
serializeEditData: function(postdata) {
return JSON.stringify(postdata);
}
};
var addSettings = {
closeAfterAdd: true,
reloadAfterSubmit: true,
closeOnEscape: true,
datatype: 'json',
serializeEditData: function(postdata) {
return JSON.stringify(postdata);
}
};
var delSettings = {
reloadAfterSubmit: true,
closeOnEscape: true,
datatype: 'json',
serializeDelData: function(postdata) {
return JSON.stringify(postdata);
}
};
$("#gridTable").jqGrid('navGrid', '#gridPager',
{ add: true, edit: true, del: true, search: false },
editSettings, // edit options
addSettings, // add options
delSettings, // del options
{}// {closeOnEscape:true}, // search options
// {height:250,jqModal:false,closeOnEscape:true} // view options
);
public class JQGridParameterBind<T> : IModelBinder
{
#region IModelBinder 成员
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var json = controllerContext.HttpContext.Request.Form[0] as string;
var jss = new JavaScriptSerializer();
return jss.Deserialize<Dictionary<string, object>>(json);
}
}
Controller
[HttpPost()]
public ActionResult Save([ModelBinder(typeof(JQGridParameterBind<Dictionary<string, object>>))] Dictionary<string, object> postdata)
{
......
}