Asp.net mvc 如何将json字符串作为json对象发送到视图?
我在MVC控制器的操作中有一个json字符串。我想将其作为JSON对象发送到视图。我怎样才能解决这个问题Asp.net mvc 如何将json字符串作为json对象发送到视图?,asp.net-mvc,json,Asp.net Mvc,Json,我在MVC控制器的操作中有一个json字符串。我想将其作为JSON对象发送到视图。我怎样才能解决这个问题 public JsonResult Json() { ... some code here ... string jsonString = "{\"Success\":true, \"Msg\":null}"; // what should I do instead of assigning jsonString to Data. return new Js
public JsonResult Json()
{
... some code here ...
string jsonString = "{\"Success\":true, \"Msg\":null}";
// what should I do instead of assigning jsonString to Data.
return new JsonResult() { Data = jsonString, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
但我建议您使用对象而不是字符串:
public ActionResult Json()
{
... some code here ...
return Json(
new
{
Success = true,
Msg = (string)null
},
JsonRequestBehavior.AllowGet
);
}
但我建议您使用对象而不是字符串:
public ActionResult Json()
{
... some code here ...
return Json(
new
{
Success = true,
Msg = (string)null
},
JsonRequestBehavior.AllowGet
);
}