如何使用JsAction获取Json值?如何acees名字?我想显示Json值的任何值。
控制器:
[JsAction()]
[HttpGet]
public JsonResult GetStudent(int a)
{
Student st = new Student() { firstName = "yusuf", lastName = "karatoprak", SumHere = 5 };
return Json(st, JsonRequestBehavior.AllowGet);
}
查看:
$(document).ready(function () {
JsActions.Home.MyTestMethod(1, 2).then(function (data) { alert(data); });
JsActions.Home.MyTestMethod2(4, 5).then(function (data) { alert(data); });
JsActions.Home.Yusuf(67, 9).then(function (data) { alert(data.toString()); });
var ret = JsActions.Home.GetStudent(6);
alert(ret.firstName);
console.log(ret.firstName);
})
但我无法访问名字。我看到一些代码形式的codeplex:
答案 0 :(得分:1)
$(document).ready(function () {
//JsActions.Home.MyTestMethod(1, 2).then(function (data) { alert(data); });
//JsActions.Home.MyTestMethod2(4, 5).then(function (data) { alert(data); });
//JsActions.Home.Yusuf(67, 9).then(function (data) { alert(data.toString()); });
// old var ret = JsActions.Home.GetStudent(6)
// new one
var ret = JsActions.Home.GetStudent(6).responseText;
alert(ret.firstName);
console.log(ret.firstName);
})
注意:您的控制器只是谈论GetStudent方法,所以我评论了其他方法调用。