Jon*_*han 3 ajax asp.net-mvc jquery
我想将一个对象传递给控制器并检索控制器中的值。我定义如下:
html代码:
var positionarray = [];
Run Code Online (Sandbox Code Playgroud)
Javascript:
$("#button").live('click',function(){
positionarray.push({
id: sessionStorage.getItem('id'),
value: $("#input").val()
});
});
// on save button click
$.ajax({
type: "GET",
url:"/Bugs/Position",
data: {
array:positionarray
},
cache: false,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (json) {
}
});
Run Code Online (Sandbox Code Playgroud)
但我无法检索控制器中的值。它越来越空了。
试试这个:- 你正在传递一个对象数组,所以你应该做 HTTPPost 而不是 HttpGet(这将适用于原始类型的数组,比如 int、strgin 等列表)通过查询字符串发送它(记住查询字符串的限制)。用 HTTPPost 试试这个
$.ajax({
type: "POST",
url:"Home/Position",
data: JSON.stringify({
array: positionarray
}),
cache: false,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (json) {
}
[HTTPPost]
public void Position(YourClass[] array){...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23136 次 |
| 最近记录: |