我想通过jQuery的ajax调用发送一些数据。我的问题是:如何在我的Insert.cshtml
文件中获得此JSON数组?我试过Request["rows"]
,Request[0][rows]
等,但没有任何成功。从jQuery中检索JSON数组在Ajax中调用asp.net网页
在这里,我要发送的数据是这个(表格多行数据):
[
{
"sl": "1",
"tname": "Gardening",
"ttype": "4",
"tduration": "12"
},
{
"sl": "2",
"tname": "Nursing",
"ttype": "4",
"tduration": "45"
}
]
jQuery代码:
$.ajax({
type: "POST",
url: "/Insert",
data: rows,
contentType: "application/json",
success: function (data, status) {
alert(status);
},
error: function (xhr, textStatus, error) {
var errorMessage = error || xhr.statusText;
alert(errorMessage);
}
});
更新:在的jsfiddle的部分演示 - http://jsfiddle.net/rafi867/gprQs/8/
也许'data [0] ['tname']'? – qwerty
@qwerty我试图访问引用页面(在这种情况下为Insert.cshtml)中的值,而不是在当前页面中。无论如何,我想你的建议会带来像“名称数据”在当前上下文中不存在的错误。 – lazylionking
你不会碰巧有一个链接到您的网站,是吗?还是一个jsfiddle? – qwerty