【发布时间】:2017-03-09 08:53:03
【问题描述】:
我已经四处搜索了几天,似乎找不到适合我的问题的解决方案。我很确定它与路由有关,但我不确定。
我收到的确切错误是:
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; }
}
我的 routingconfig 文件如下所示:
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
}
);
}
我应该提到,我已将每个视图页面的所有属性设置为内容的构建操作,之前它们是“无”,但这也没有解决问题。
编辑: 我忘了提一下,当我在本地环境中调试时它工作得非常好,当它尝试在网络服务器上运行时它开始中断。
编辑 2:我已将堆栈跟踪添加到我最初的问题以及模型和一些修饰。
编辑 3:最后一件事是,为了访问我尝试以 2 种不同方式从视图执行此操作的页面。第一种方法是:
@Html.ActionLink("Report Details", "Reporting", "Reporting")
第二个在做:
<a href="../Reporting/Reporting">
<span>Report Details</span>
</a>
【问题讨论】:
标签: c# asp.net-mvc asp.net-mvc-5 asp.net-mvc-routing