Reputation: 2966
How to get Json value by using JsAction? How to acees firstname? i would like to show any value from Json value.
Controller:
[JsAction()]
[HttpGet]
public JsonResult GetStudent(int a)
{
Student st = new Student() { firstName = "yusuf", lastName = "karatoprak", SumHere = 5 };
return Json(st, JsonRequestBehavior.AllowGet);
}
View:
$(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);
})
But i can not access firstname. i see some code form codeplex:
Upvotes: 1
Views: 1034
Reputation: 14297
$(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);
})
Note: your controller just speaks about GetStudent method so I commented other method calls.
Upvotes: 1