I'm trying to check if a couple of views exist by using paths. But the views cannot be found even if they do exist.
private string SelectFirstView(ControllerContext ctx, params string[] viewNames)
{
return viewNames.First(view => ViewExists(ctx, view));
}
private bool ViewExists(ControllerContext ctx, string name)
{
var result = ViewEngines.Engines.FindView(ctx, name, null);
return result.View != null;
}
And how I try to find the views:
var viewName = SelectFirstView(ctx, statusCodeName,
"~/Error/" + statusCodeName,
"~/Error/General",
"~/Shared/Error",
"Error");
Note that "~/Shared/Error"
and "Error"
is the same view, but only the latter is found.