【问题标题】:Avoid using _Layout-cshtml in asp.net-mvc避免在 asp.net-mvc 中使用 _Layout-cshtml
【发布时间】:2017-11-24 09:08:57
【问题描述】:

这是我的 _ViewStart.cshtml:

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

这是我的 _Layout.html:

<!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>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">


    <!-- Lots of tags for dependencies -->

</head>
<body>
    <div class="container body-content">
        @RenderBody()
        <div class="divider row top-buffer"></div>
        <footer>
            <p>&copy; @DateTime.Now.Year - MyApp</p>
        </footer>
    </div>
</body>
</html>

这是我的 Index.cshtml:

@Html.RenderApiEndpoints()
<script type="text/javascript" src="~/Content/index.js"></script>

    <div ng-app="app">
        <div ng-view ></div>
    </div>

我正在获取 Index.cshtml 之类的:

public class HomeController : Controller
    {
        [Route("")]
        public ActionResult Index()
        {
            return View();
        }
    }

由于我使用带有 Angular $routeProvider 的客户端路由,因此我总是在 Index.cshtml 中。此外,我不需要布局,我只需要我的 Index.cshtml。

在浏览器中访问本地主机时,如何避免使用布局文件并直接从我的 Index.cshtml 开始?

【问题讨论】:

  • @testiguy 你解决问题了吗

标签: asp.net .net angularjs asp.net-mvc url-routing


【解决方案1】:

你可以将Layout设为null,那么你只会看到Index.cshtml view

@{
    Layout = null;
}

【讨论】:

  • 那我用Index.cshtml自动启动?
  • @testiguy 是的,你可以开始
  • @testiguy 你试过了吗
【解决方案2】:

按以下方式使用空布局:

@{
    Layout = null;
}

【讨论】:

  • 这等于我的答案
猜你喜欢
  • 2015-03-18
  • 2011-06-12
  • 2013-03-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多