避免在 asp.net-mvc 中使用 _Layout-cshtml
Avoid using _Layout-cshtml in asp.net-mvc
这是我的 _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>© @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 开始?
您可以将 Layout
设置为 null 然后您将只看到 Index.cshtml view
@{
Layout = null;
}
按以下方式使用空布局:
@{
Layout = null;
}
这是我的 _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>© @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 开始?
您可以将 Layout
设置为 null 然后您将只看到 Index.cshtml view
@{
Layout = null;
}
按以下方式使用空布局:
@{
Layout = null;
}