避免使用_layout-CSHTML在asp.net-MVC

问题描述:

这是我_ViewStart.cshtml:避免使用_layout-CSHTML在asp.net-MVC

@{ 
    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开始?

+0

@ testiguy你解决问题 – hasan

您可以Layout空,那么你只会看到Index.cshtml view

@{ 
    Layout = null; 
} 
+0

然后,我与指数自动启动。 CSHTML? – testiguy

+0

@testiguy是的你可以开始 – hasan

+0

@testiguy你试过 – hasan

使用null布局以下列方式:

@{ 
    Layout = null; 
} 
+0

这等于我的回答 – hasan