MVC 4 JsonResult渲染原始字符串而不是View

时间:2014-12-06 13:47:46

标签: asp.net-mvc jsonresult

这是一个真正的初学者问题,希望你能帮我快速回答。

当我调用JsonResult类型的动作时,视图呈现为原始Json而不是我创建的预期定义视图。

这就是我在浏览器中看到的所有内容:

[{"Name":"xx","Description":"xx","Address":"xx","Town":"xx","PostCode":"xx","Enabled":true,"pkId":1},{"Name":"xx","Description":"xx","Address":"xx","Town":"xx","PostCode":"xxx","Enabled":true,"pkId":3}]

这是我的行动:

public JsonResult SubmitFeedback()
    {
        PropertyInspectionContext context = new PropertyInspectionContext();
        var prop = context.Property;
        return Json(prop, JsonRequestBehavior.AllowGet);

    }

谢谢,

1 个答案:

答案 0 :(得分:0)

如果您已经创建了JsonResult(Json),那么返回JsonString。

如果你想View应该返回Html标记和模型组合,那么你应该返回查看结果。

public ActionResult SubmitFeedback()
    {
        PropertyInspectionContext context = new PropertyInspectionContext();
        var prop = context.Property;

        //return Json(prop, JsonRequestBehavior.AllowGet);
        return View(your view name,prop);   

    }