为什么布局没有集成

时间:2016-07-06 14:22:59

标签: c# razor asp.net-web-api katana

我有一个在Katana上运行的ASP.NET Web API,并使用Razorengine生成视图。

所以我创建了一个没有布局的视图,它按预期工作 的 View.cshtml

<h2>View</h2>

在浏览器上 enter image description here

所以当我要添加如下布局时:

@{
    ViewBag.Title = "View";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>View</h2>

请求后,我只有一个空白网站。

我做错了什么? enter image description here

更新

控制器代码:

public class CustomersController : ApiController
  {
    [HttpGet]
    [Route("customers")]
    public IHttpActionResult View()
    {
      return new ViewResult(Request, @"Customers\View", null);
    }

  }

和_ Layout.cshtml

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                @Html.ActionLink("Application name", "Index", "Home", new { area = "" }, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <ul class="nav navbar-nav">
                </ul>
            </div>
        </div>
    </div>

    <div class="container body-content">
        @RenderBody()
        <hr />
        <footer>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
        </footer>
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/bootstrap")
    @RenderSection("scripts", required: false)
</body>
</html>

但是当我用其他结构替换布局时:

<!DOCTYPE html>
<html>
  <head>
    <title>Page Title</title>
  </head>
  <body>

  @RenderBody()

  </body>
</html>

然后它有效。布局模板错误。

0 个答案:

没有答案