我有一个问题,如果使用Return Json()将数据从Action方法返回到json,我会遇到奇怪的行为
这段代码总是让我警惕“成功”
//In action method in controller
//either
return Json(true);
//or
return Json(false);
//In view
success: function (data) {
if (data) {
alert("success");
} else {
alert("failed");
}
}
这段代码总是让我警惕“失败”
//In action method in controller
//either
return Json(new { success = true });
//or
return Json(new { success = false });
success: function (data) {
if (data.success) {
alert("success");
} else {
alert("failed");
}
}
这段代码总是让我警惕“失败”
//In action method in controller
//either
return Json(new { success = "true" });
//or
return Json(new { success = "false" });
success: function (data) {
if (data.success == "true") {
alert("success");
} else {
alert("failed");
}
}
我正在使用visual studio 2015,需要你的解释先生。谢谢