如何通过从MVC的控制器Ajax调用多个参数
我有一个像下面的控制器:
I have the controller like the below:
public ActionResult Save(string input, string name)
{
//Some code
return PartialView();
}
和我需要一个AJAX调用该控制器的方法,并通过两个参数输入值
And I need an ajax call to this controller method and pass the two arguments input and value
和我的ajax调用就像如下:
And my ajax call is like the below:
$.ajax({
url: '/Home/Save',
type: 'POST',
async: false,
dataType: 'text',
processData: false,
data: "input=" + JSON.stringify(data) + "&name =" + $("#name").val(),
success: function (data) {
}
});
我无法传递值的名称参数.. 在名称参数的值越来越空..请帮助我.. 在此先感谢
I am unable to pass the value to the name parameter.. the value in the name parameter is becoming null .. please help me .. Thanks in advance
您正在做一个HTTP POST,而是试图通过与GET查询字符串语法参数。在后,数据传递命名的参数,并且不使用参数=值放大器;富=酒吧
语法。使用jQuery的Ajax方法可以让你创建一个JavaScript对象与指定的参数,例如:
You're making an HTTP POST, but trying to pass parameters with the GET query string syntax. In a POST, the data are passed as named parameters and do not use the param=value&foo=bar
syntax. Using jQuery's ajax method lets you create a javascript object with the named parameters, like so:
$.ajax({
url: '/Home/SaveChart',
type: 'POST',
async: false,
dataType: 'text',
processData: false,
data: {
input: JSON.stringify(IVRInstant.data),
name: $("#wrkname").val()
},
success: function (data) { }
});