Adding sub-directory to “View/Shared” folder in AS

2019-01-08 09:50发布

I'm currently developing a site using ASP.Net MVC3 with Razor. Inside the "View/Shared" folder, I want to add a subfolder called "Partials" where I can place all of my partial views (for the sake of organizing the site better.

I can do this without a problem as long as I always reference the "Partials" folder when calling the views (using Razor):

@Html.Partial("Partials/{ViewName}")

My question is if there is a way to add the "Partials" folder to the list that .Net goes through when searching for a view, this way I can call my view without having to reference the "Partials" folder, like so:

@Html.Partial("{ViewName}")

Thanks for the help!

7条回答
SAY GOODBYE
2楼-- · 2019-01-08 10:39

It´s nice to custom the view engine, but if you just want to have a subfolder por partials you don´t need that much...

Just use the full path to the partial view, as done for the Layout View:

@Html.Partial("/Views/Shared/Partial/myPartial.cshtml")

Hope it helps someone...

查看更多
登录 后发表回答