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

2019-07-23 19:04发布

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条回答
ゆ 、 Hurt°
2楼-- · 2019-07-23 19:31

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;
 }
查看更多
登录 后发表回答