主要用于返回json格式对象,可以用ajax操作;
注意:需要设置参数,JsonRequestBehavior.AllowGet,
否则会提示错误:此请求已被阻止,因为当用在 GET 请求中时,会将敏感信息透漏给第三方网站。
若要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet。
代码示例:
-------------------------------------
public ActionResult Json()
{
Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("id", 100);
dic.Add("name", "hello");
return Json(dic, JsonRequestBehavior.AllowGet);
}
------------------------
public ActionResult Json()
{
JsonResult result = new JsonResult();
result.Data = new
{
state = "Authentication Failed"
};
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;
}
----------------------------------------
注意:需要设置参数,JsonRequestBehavior.AllowGet,
否则会提示错误:此请求已被阻止,因为当用在 GET 请求中时,会将敏感信息透漏给第三方网站。
若要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet。
代码示例:
-------------------------------------
public ActionResult Json()
{
Dictionary<string, object> dic = new Dictionary<string, object>();
dic.Add("id", 100);
dic.Add("name", "hello");
return Json(dic, JsonRequestBehavior.AllowGet);
}
------------------------
public ActionResult Json()
{
JsonResult result = new JsonResult();
result.Data = new
{
state = "Authentication Failed"
};
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;
}
----------------------------------------