asp.net mvc razor: How to directly access .cshtml page?

霸气de小男生 提交于 2019-12-11 03:34:19

问题


How can i directly access a .cshtml file in ASP.NET MVC using razor view engine?

For example i have this url: localhost/Home/About. This will load the about site inside the "master" page.

I want to load the about page without also loading the master page. So i was thinking that i could use this url: localhost/Home/About.cshtml. But it's not working.

How can i load a view page without loading the master page?


回答1:


You can use the method Html.Partial like this:

@Html.Partial("About")

Edit

I might have missunderstood your question. If you want to avoid including the master page you need to remove the layout.

Add this to the top of your View:

@{
     Layout = null;
 }


来源:https://stackoverflow.com/questions/4942634/asp-net-mvc-razor-how-to-directly-access-cshtml-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!