【发布时间】:2012-07-10 08:00:19
【问题描述】:
我有一个视图,我从中调用另一个视图来在我的 html 中的脚本标记内呈现一些 json:
public ActionResult App()
{
return View();
}
public JsonResult SomeJsonData()
{
// ... here goes the code that generates the model
return Json(model, JsonRequestBehavior.AllowGet);
}
在我的 App.cshtml 文件中,我有这样的内容:
<script type='text/javascript'>
var myJsonData = @Html.Action("SomeJsonData", "MyController");
</script>
问题是,有时当我在浏览器中重新加载页面(现在使用 Chrome 20)时,它会显示所有标记,如果我转到开发人员工具中的网络选项卡,我可以看到 Content-Type页面请求的类型为“application/json”。如果我只是重新加载页面,那么它会正确加载(内容类型应该是“text/html”)。
知道为什么会发生这种情况吗?还是我做错了什么?
【问题讨论】:
标签: asp.net-mvc json content-type