问题
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