当我正在开发 Asp.Net MVC 应用程序时,在我的应用程序中我使用jQuery.POST
提交表单的方法。
e.g.
jQuery.post('/Product/Save', jQuery(document.forms[0]).serialize(),
function (data) { alert('Product Added Successfully.); }
);
在上面的代码片段中,我想传递另一个参数..比方说..ProductID
.
所以,我的想法是,我想同时通过jQuery(document.forms[0]).serialize()
and ProductID variable
in jQuery.POST method
,所以我可以同时得到Form and ProductID
in my controller's action method
.
有人可以让我知道我会这样做吗?
提前致谢。
你可以使用以下插件 https://stackoverflow.com/questions/1184624/serialize-form-to-json-with-jquery将表单序列化为 JSON 对象并添加其他参数:
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
像这样:
var data = $('form').serializeObject();
data['ProductId'] = '123';
$.post('<%= Url.Action("Save", "Product") %>', data, function (data) {
alert('Product Added Successfully.');
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)