尝试将 FindView 与路径一起使用
我正在尝试使用路径检查是否存在几个视图。但即使存在,也无法找到这些视图。
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;
}
以及我如何尝试查找视图:
var viewName = SelectFirstView(ctx, statusCodeName,
"~/Error/" + statusCodeName,
"~/Error/General",
"~/Shared/Error",
"Error");
请注意, "~/Shared/Error"
和 "Error"
是相同的视图,但仅找到后者。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用路径时,您还需要指定扩展名:
当您不指定路径时,您不需要扩展名,因为在这种情况下,视图引擎遵循标准约定来发现视图。
When you are working with paths you need to specify the extension as well:
When you don't specify a path you don't need the extension as in this case the view engine follows standard conventions to discover the views.