查看找不到布局页面

问题描述 投票:1回答:3

我的观点找不到布局。但一切看起来都很好。我的结构如下图所示。

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

为什么我得到这个异常?本来工作得很好,但我的视图找不到布局。

asp.net asp.net-mvc
3个回答
2
投票

还有请问View Controller的全部内容?

在不看View Controller的情况下,一些可能的情况是;-一些部分丢失了(如 "DocumentReady")-视图正在尝试解析没有设置的模型属性(即null)


0
投票

你可以检查你的_MainLayout.cshtml文件的属性设置。我也有同样的问题(在搜索路径中找不到Layout页面),直到我将VisualStudio属性BuildAction设置为Content。我复制了这个文件并重新命名,而且这个属性被设置为 "none"。


-4
投票

这就是你的问题。Layout = "~/Views/_MainLayout.cshtml";

_Layout的引用应该是 Layout = "~/Views/Shared/_MainLayout.cshtml";

不要再犯这种错误了!

© www.soinside.com 2019 - 2024. All rights reserved.