0

I followed this tutorial to customize my partial views locations. http://www.leonamarant.com/2011/02/17/adding-a-custom-directory-to-razor-view-engine-partial-view-locations-in-asp-net-mvc3/

Everything is ok except one thing : define a custom location with a controller name.
Here is my locations :

private static string[] customLocations = new[] {
    "~/Views/{1}/{0}.cshtml",       // It does not work
    "~/Views/Shared/{0}.cshtml",    // It works
    "~/Views/Home/{0}.cshtml"       // It works
};

In my view, I just add this line and the partial view is not found :

@Html.Partial("Test/_MyPartial")

I know that I could write a relative path to resolve my problem but this line does not require my class "MyViewEngine.cs"

@Html.Partial("../Test/_MyPartial")

How can I bind my controller name with the {1} ?

spritus
  • 123
  • 1
  • 7
  • "~/Views/{1}/{0}.cshtml" is a default location where Razor view engine looks where {1} is the controller name rit.So you dont need to define a custom location for this in you class. So also in your case @Html.Partial("_MyPartial") may works. – ssilas777 Jul 26 '12 at 14:17
  • I know what you mean but in my case, I try to display 2 partial views from a different controller. Imagine a MediaController with ~/Views/Media/List.cshtml and this view include 2 partial views : ~/Views/Picture/_List.cshtml and ~/Views/Video/_List.cshtml – spritus Jul 30 '12 at 09:59

0 Answers0