Show current search paths for a view

2019-07-27 14:35发布

问题:

I'm trying to troubleshoot a view and why it can't find the editor templates. Obviously it has to do with how we've configured the search paths in the CustomRazorViewEngine, but just looking at it, it should be working. Instead, it's rendering the default MVC editor templates, because it can't find the custom ones.

How can I display the list of search paths for a view, or trigger an error so that it shows me the search paths it's looking for?

回答1:

This may not be the best way, but adding this to the controller worked for me:

var searchedLocations = ViewEngines.Engines.[0]
    .FindPartialView(this.ControllerContext, "MyModel", false)
    .SearchedLocations
    .ToArray();