Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Html.Partial() method to render partial view with an explicit path

Everyone, I'm using MVC 3 (Razor). I have the following problem:

I have some common contents segregated into a partial view. But rather than to put it in the default location (views/shared or views/controller-name), I need to put it in a different location (views/shared/new-folder or view/controller-name/new-folder).

I tried this : @Html.Partial("views/shared/new-folder/partial-view-name") or even @Html.Partial("views/shared/new-folder/partial-view-name.cshtml"),but it seems that MVC3 only consider the parameter as a view name, and it totally ignored any path information.

Maybe I did something wrong ,can anybody help me with this ?:) Thank you very much!

like image 491
NextStep Avatar asked Oct 11 '11 00:10

NextStep


1 Answers

You need to reference using an application virtual path (notice the ~\ at the beginning of the path):

@Html.Partial("~\\views\\shared\\new-folder\\partial-view-name.cshtml")
like image 69
marcind Avatar answered Oct 26 '22 20:10

marcind