jQuery.SerializeArray如何向其中添加更多参数? [英] Jquery.SerializeArray how to add more parameters to it?
问题描述
我正在对表单进行序列化,以将其发送回自动绑定到视图模型的服务器.但是想再发送2个参数到服务器,但不确定如何
I am serializing my form to be sent back to the server where it auto binds to a view model. However want to send 2 more parameters to the server but not sure how
public ActionResult Test(MyViewModel vm, DateTime date, bool isSomething)
我不确定ajax调用中的数据"参数应该是什么样子
I am not sure how my "data" parameter in my ajax call should look like
data: { 'vm': frm, 'date': date, 'isSomething': true }, // this does not work.
通常我会这样做
data: frm,
我的代码符合并且没有JavaScript错误,但是它在所有frm后面都附加了"vm",然后在服务器上它不知道如何绑定它.基本上json键会弄乱绑定.
My code complies and no javascript errors however it appends 'vm' to all of the frm ones and then on the server it does not know how to bind it. Basically the json key is messing up the binding.
我这样做
data: frm // result of items look like this Id 7b97dcc7-3f8d-4cc0-ad2a-a104010f683d
当我这样做
data: {'vm' : frm} // result looks like this vm[0][name] Id
一些我必须发送它的方式,所以它确实需要一个密钥.
some how I have to send it so it does need a key.
推荐答案
您的操作方法中存在语法错误
There is a syntax error in your action method
public ActionResult Test(MyViewModel, vm, DateTime date, bool isSomething)
应该是
public ActionResult Test(MyViewModel vm, DateTime date, bool isSomething)
您可能还希望将其添加到您的jquery ajax调用中
You may also want to add this to your jquery ajax call
data: { 'vm': frm, 'date': date, 'isSomething': true },
traditional: true
它将允许您使用param序列化的传统样式."
It will allow for you to "use the traditional style of param serialization."
这篇关于jQuery.SerializeArray如何向其中添加更多参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!