1

If I have understod this right.. the razor view engine is specified to only allow HtmlHelper editables for the default paths.. but what if I change or extend the paths for where the engine should look for my partial views and then want to be able to use Html.EditorFor() with in one of those partials... is there anyway to get the Html.EditorFor to work with this custom path as well?

Inx
  • 2,364
  • 7
  • 38
  • 55

1 Answers1

0

Yes you will still be able to use the Html.EditorFor because they will just use all your view engines to resolve the view you are looking for. If you want to see an example of how you can create your own view engine with new paths, take a look at this view engine from one of my projects.

https://github.com/stevehodgkiss/restful-routing/blob/master/src/RestfulRouting/ViewEngines/RestfulRoutingRazorViewEngine.cs

public class RestfulRoutingRazorViewEngine : RazorViewEngine
{
    public RestfulRoutingRazorViewEngine()
    {
        AreaMasterLocationFormats = new[] {
                                              "~/Views/{2}/{1}/{0}.cshtml",
                                              "~/Views/{2}/{1}/{0}.vbhtml",
                                              "~/Views/{2}/Shared/{0}.vbhtml",
                                              "~/Views/{2}/Shared/{0}.cshtml",
                                          };

        AreaViewLocationFormats = new[] {
                                            "~/Views/{2}/{1}/{0}.cshtml",
                                            "~/Views/{2}/{1}/{0}.vbhtml",
                                            "~/Views/{2}/Shared/{0}.cshtml",
                                            "~/Views/{2}/Shared/{0}.vbhtml",
                                        };

        AreaPartialViewLocationFormats = AreaViewLocationFormats;
    }
}

I still use the EditorFor to figure out my views for Editors and Display templates.

Khalid Abuhakmeh
  • 10,709
  • 10
  • 52
  • 75