查看无法找到布局页面

时间:2013-08-04 23:26:47

标签: asp.net asp.net-mvc

我的视图无法找到布局。但一切看起来都很好。我的结构如下所示:

enter image description here

我的观点如下所示:

@model xxx.Web.Model.Home.IndexModel
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/_MainLayout.cshtml";
}

我的布局如下所示:

<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="utf-8">
<title>Bootstrappage:Free Bootstrap Template (bootstrap 2.3.1 version)</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- 
<link rel="stylesheet" href="themes/style/bootstrap.min.css" />
<link rel="stylesheet" href="themes/style/bootstrap-responsive.min.css" />
-->
<link rel="stylesheet/less" type="text/css" href="../../themes/less/bootstrap.less">
<script src="../../themes/js/less/less.js" type="text/javascript"></script>
<link rel="shortcut icon" href="assets/ico/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="assets/ico/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="assets/ico/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="assets/ico/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="assets/ico/apple-touch-icon-57-precomposed.png">
<script type="text/javascript">
    $(function () {
        @RenderSection("DocumentReady", false)
    });
</script>
</head>
<body data-offset="40">
@{Html.RenderAction("Header", "Partial");}
@{Html.RenderAction("Navbar", "Partial");}
@RenderBody()
@{Html.RenderAction("Footer", "Partial");}
<script src="themes/js/lib/jquery-1.9.1.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>

</body>
</html>

我的控制器如下所示:

 public ActionResult Index()
    {
        IndexModel model = new IndexModel();
        HomeModelFactory modelFactory = new HomeModelFactory();
        model.Files = modelFactory.CreateIndexModel();

        return View(model);
    }

异常: enter image description here

为什么我会收到此异常?它运作良好。

3 个答案:

答案 0 :(得分:2)

视图/控制器的全部内容也好吗?

不看View / Controller的一些可能情况是; - 缺少某些部分(例如“DocumentReady”) - 视图正在尝试解析未设置的模型属性(即null)

答案 1 :(得分:0)

您可以在_MainLayout.cshtml文件中检查属性设置。在将Visual Studio属性BuildAction设置为Content之前,我遇到了同样的问题(在搜索路径中找不到Layout页面)。我已经复制了文件并将其重命名,并且该属性已设置为“无”。

答案 2 :(得分:-4)

这是您的问题:Layout = "~/Views/_MainLayout.cshtml";

_Layout引用应为Layout = "~/Views/Shared/_MainLayout.cshtml";

不要再犯这些错误了!