未找到视图 'Reporting' 或其母版,或者没有视图引擎支持搜索的位置
The view 'Reporting' or its master was not found or no view engine supports the searched locations
我已经搜索了几天,但似乎找不到适合我的问题的解决方案。我很确定它与路由有关,但我不确定。
我收到的确切错误是:
The view 'Reporting' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Reporting/Reporting.aspx
~/Views/Reporting/Reporting.ascx
~/Views/Shared/Reporting.aspx
~/Views/Shared/Reporting.ascx
~/Views/Reporting/Reporting.cshtml
~/Views/Reporting/Reporting.vbhtml
~/Views/Shared/Reporting.cshtml
~/Views/Shared/Reporting.vbhtml
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The view 'Reporting' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Reporting/Reporting.aspx
~/Views/Reporting/Reporting.ascx
~/Views/Shared/Reporting.aspx
~/Views/Shared/Reporting.ascx
~/Views/Reporting/Reporting.cshtml
~/Views/Reporting/Reporting.vbhtml
~/Views/Shared/Reporting.cshtml
~/Views/Shared/Reporting.vbhtml
Stack Trace:
[InvalidOperationException: The view 'Reporting' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Reporting/Reporting.aspx
~/Views/Reporting/Reporting.ascx
~/Views/Shared/Reporting.aspx
~/Views/Shared/Reporting.ascx
~/Views/Reporting/Reporting.cshtml
~/Views/Reporting/Reporting.vbhtml
~/Views/Shared/Reporting.cshtml
~/Views/Shared/Reporting.vbhtml]
System.Web.Mvc.ViewResult.FindView(ControllerContext context) +502
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +143
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +90
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +833
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +186
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137
我的 Web 应用程序中的每个页面都出现此错误,但是无论我执行 URL 还是键入 /Home/Index,我的主页都可以正常工作。
我的控制器内部方法名称与我的视图名称匹配
public ActionResult Reporting()
{
var model = new DashboardCurrentRelease
{
ApplicationNames = GetApplications()
};
return View("Reporting", (object)model);
}
GetApplications() 方法如下所示:
private IEnumerable<SelectListItem> GetApplications()
{
var applications = new DashboardViewModel();
var applicationList = applications.DashboardCurrentReleases.Select(x => new SelectListItem
{
Value = x.ApplicationName.ToString(),
Text = x.ApplicationName
});
return new SelectList(applicationList, "Value", "Text");
}
这是我的模型的样子:
public partial class DashboardViewModel : DbContext
{
public DashboardViewModel()
: base("name=DashboardViewModel1")
{
}
public virtual DbSet<DashboardCurrentRelease> DashboardCurrentReleases { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<DashboardCurrentRelease>()
.Property(e => e.ApplicationName)
.IsUnicode(false);
modelBuilder.Entity<DashboardCurrentRelease>()
.Property(e => e.Release)
.IsUnicode(false);
}
}
[Table("DashboardCurrentRelease")]
public partial class DashboardCurrentRelease
{
[Display(Name = "Application Name")]
public IEnumerable<SelectListItem> ApplicationNames { get; set; }
[Key]
[Column(Order = 0)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int ApplicationKey { get; set; }
[StringLength(50)]
public string ApplicationName { get; set; }
[StringLength(50)]
public string Release { get; set; }
public int? FailCnt { get; set; }
public int? PassCnt { get; set; }
public int? OtherCnt { get; set; }
public int? ExecutedCnt { get; set; }
public int? NotExecutedCnt { get; set; }
}
我的路由配置文件如下所示:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
}
关于如何解决我的问题有什么想法吗?我没有正确执行 RouteConfig 吗?我读到它必须首先是最不具体的路线,然后才是最具体的路线,但它仍然不想为我工作。
另外一个我试过没有成功的Route Config也是这个:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Reporting", "{controller}/{action}",
new
{
controller = "Reporting",
action = "Reporting"
});
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
}
我应该提到我已经将每个视图页面的所有属性设置为内容的构建操作,它们之前是 'None' 但这也没有解决问题。
编辑:
我忘了说,当我在我的本地环境中调试时,它工作得很好,当我试图在网络服务器上 运行 时,它开始崩溃。
编辑 2:我已将堆栈跟踪添加到我最初的问题以及模型和一些修改。
编辑 3:最后一件事是,要到达我尝试以 2 种不同方式从视图进行的页面。第一种方法是:
@Html.ActionLink("Report Details", "Reporting", "Reporting")
第二个是:
<a href="../Reporting/Reporting">
<span>Report Details</span>
</a>
在MVC中,路由引擎,用于解析传入和传出的URL组合,如果你遵循路由引擎使用的Convention(规则),你不必更改Configuration .我真的只对区域或 MVC 约定之外的任何内容使用自定义路由。而且您的约定似乎遵循 MVC 的指导方针,文件夹和控制器相互匹配。所以我认为您不需要自定义路线。
ASP.net MVC 的路由引擎不提供网页 (.cshtml)。它为代码中的 Class 提供了一种 URL 处理方式,可以将 text/html 渲染到输出流,或者以一致的方式解析和提供 .cshtml 文件使用公约。您的视图引擎是从以控制器命名的目录中提供网页 (.cshtml) 文件的引擎。这就是说路由引擎控制 URL。你试过了吗**return View("NameOfView", Model);**
您需要注意其他事项,例如确保名称空间正确,以及是否从模型中获取字符串?你们中的它必须正确格式化为 return View("Message",(object)msg);
而不是 return View("Message",msg);
因为我看不到你的模型或你的视图,并且没有发布完整的堆栈跟踪很难说为什么你的视图是没有显示。当然,如果您展示了一个正在使用更改名称调用的 URL,那也很好。但我能想到的主要是模型和/或名称空间,另外,如果您从视图中调用 Layout = "~/Views/Shared/_Layout.cshtml";
或者您是否依赖于 _ViewStart
文件。还要检查您是否从菜单或 link 调用了正确的操作。 @Html.Action
方法实际上调用控制器并呈现视图,您是否尝试使用智能感知来查看 ActionLink 的重载,(@Html.ActionLink("Some text","Action","Controller", new {id=1}, null)
),只是为了确保您从 link。希望这能为您指明解决方案的正确方向。
我已经搜索了几天,但似乎找不到适合我的问题的解决方案。我很确定它与路由有关,但我不确定。
我收到的确切错误是:
The view 'Reporting' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Reporting/Reporting.aspx
~/Views/Reporting/Reporting.ascx
~/Views/Shared/Reporting.aspx
~/Views/Shared/Reporting.ascx
~/Views/Reporting/Reporting.cshtml
~/Views/Reporting/Reporting.vbhtml
~/Views/Shared/Reporting.cshtml
~/Views/Shared/Reporting.vbhtml
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: The view 'Reporting' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Reporting/Reporting.aspx
~/Views/Reporting/Reporting.ascx
~/Views/Shared/Reporting.aspx
~/Views/Shared/Reporting.ascx
~/Views/Reporting/Reporting.cshtml
~/Views/Reporting/Reporting.vbhtml
~/Views/Shared/Reporting.cshtml
~/Views/Shared/Reporting.vbhtml
Stack Trace:
[InvalidOperationException: The view 'Reporting' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Reporting/Reporting.aspx
~/Views/Reporting/Reporting.ascx
~/Views/Shared/Reporting.aspx
~/Views/Shared/Reporting.ascx
~/Views/Reporting/Reporting.cshtml
~/Views/Reporting/Reporting.vbhtml
~/Views/Shared/Reporting.cshtml
~/Views/Shared/Reporting.vbhtml]
System.Web.Mvc.ViewResult.FindView(ControllerContext context) +502
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context) +143
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +90
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult) +833
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +81
System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +186
System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +38
System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +36
System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +38
System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +44
System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +65
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +38
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +399
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +137
我的 Web 应用程序中的每个页面都出现此错误,但是无论我执行 URL 还是键入 /Home/Index,我的主页都可以正常工作。
我的控制器内部方法名称与我的视图名称匹配
public ActionResult Reporting()
{
var model = new DashboardCurrentRelease
{
ApplicationNames = GetApplications()
};
return View("Reporting", (object)model);
}
GetApplications() 方法如下所示:
private IEnumerable<SelectListItem> GetApplications()
{
var applications = new DashboardViewModel();
var applicationList = applications.DashboardCurrentReleases.Select(x => new SelectListItem
{
Value = x.ApplicationName.ToString(),
Text = x.ApplicationName
});
return new SelectList(applicationList, "Value", "Text");
}
这是我的模型的样子:
public partial class DashboardViewModel : DbContext
{
public DashboardViewModel()
: base("name=DashboardViewModel1")
{
}
public virtual DbSet<DashboardCurrentRelease> DashboardCurrentReleases { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<DashboardCurrentRelease>()
.Property(e => e.ApplicationName)
.IsUnicode(false);
modelBuilder.Entity<DashboardCurrentRelease>()
.Property(e => e.Release)
.IsUnicode(false);
}
}
[Table("DashboardCurrentRelease")]
public partial class DashboardCurrentRelease
{
[Display(Name = "Application Name")]
public IEnumerable<SelectListItem> ApplicationNames { get; set; }
[Key]
[Column(Order = 0)]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public int ApplicationKey { get; set; }
[StringLength(50)]
public string ApplicationName { get; set; }
[StringLength(50)]
public string Release { get; set; }
public int? FailCnt { get; set; }
public int? PassCnt { get; set; }
public int? OtherCnt { get; set; }
public int? ExecutedCnt { get; set; }
public int? NotExecutedCnt { get; set; }
}
我的路由配置文件如下所示:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
}
关于如何解决我的问题有什么想法吗?我没有正确执行 RouteConfig 吗?我读到它必须首先是最不具体的路线,然后才是最具体的路线,但它仍然不想为我工作。
另外一个我试过没有成功的Route Config也是这个:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Reporting", "{controller}/{action}",
new
{
controller = "Reporting",
action = "Reporting"
});
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
}
);
}
我应该提到我已经将每个视图页面的所有属性设置为内容的构建操作,它们之前是 'None' 但这也没有解决问题。
编辑: 我忘了说,当我在我的本地环境中调试时,它工作得很好,当我试图在网络服务器上 运行 时,它开始崩溃。
编辑 2:我已将堆栈跟踪添加到我最初的问题以及模型和一些修改。
编辑 3:最后一件事是,要到达我尝试以 2 种不同方式从视图进行的页面。第一种方法是:
@Html.ActionLink("Report Details", "Reporting", "Reporting")
第二个是:
<a href="../Reporting/Reporting">
<span>Report Details</span>
</a>
在MVC中,路由引擎,用于解析传入和传出的URL组合,如果你遵循路由引擎使用的Convention(规则),你不必更改Configuration .我真的只对区域或 MVC 约定之外的任何内容使用自定义路由。而且您的约定似乎遵循 MVC 的指导方针,文件夹和控制器相互匹配。所以我认为您不需要自定义路线。
ASP.net MVC 的路由引擎不提供网页 (.cshtml)。它为代码中的 Class 提供了一种 URL 处理方式,可以将 text/html 渲染到输出流,或者以一致的方式解析和提供 .cshtml 文件使用公约。您的视图引擎是从以控制器命名的目录中提供网页 (.cshtml) 文件的引擎。这就是说路由引擎控制 URL。你试过了吗**return View("NameOfView", Model);**
您需要注意其他事项,例如确保名称空间正确,以及是否从模型中获取字符串?你们中的它必须正确格式化为 return View("Message",(object)msg);
而不是 return View("Message",msg);
因为我看不到你的模型或你的视图,并且没有发布完整的堆栈跟踪很难说为什么你的视图是没有显示。当然,如果您展示了一个正在使用更改名称调用的 URL,那也很好。但我能想到的主要是模型和/或名称空间,另外,如果您从视图中调用 Layout = "~/Views/Shared/_Layout.cshtml";
或者您是否依赖于 _ViewStart
文件。还要检查您是否从菜单或 link 调用了正确的操作。 @Html.Action
方法实际上调用控制器并呈现视图,您是否尝试使用智能感知来查看 ActionLink 的重载,(@Html.ActionLink("Some text","Action","Controller", new {id=1}, null)
),只是为了确保您从 link。希望这能为您指明解决方案的正确方向。