我现在已经搜索了几天,似乎找不到适合我问题的解决方案。我很确定它与路由有关,但我不确定。
我收到的确切错误是:
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
我在我的网络应用程序中的每个页面上都收到此错误,但无论我是否使用URL或键入/ Home / Index,我的主页都在工作。
我的Controller方法名称内部与我的视图名称匹配
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吗?我读到它必须是最不具体的路线,然后是最具体的路线,但它仍然不想为我工作。
我尝试过的另一个路线配置也没有成功:
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
}
);
}
我应该提一下,我已经将每个View页面的所有属性设置为内容的构建操作,之前它们是“无”,但也没有解决问题。
编辑: 我忘了提一下,当我在我的本地环境中进行调试时,它运行得非常好,当它试图在网络服务器上运行它开始破坏时。
编辑2:我已经将堆栈跟踪添加到我的初始问题以及模型和一些修改中。
编辑3:最后一件事就是到达页面我试图以两种不同的方式从视图中做到这一点。第一种方式是:
@Html.ActionLink("Report Details", "Reporting", "Reporting")
第二个是:
<a href="../Reporting/Reporting">
<span>Report Details</span>
</a>
答案 0 :(得分:0)
在MVC中,路由引擎用于解析传入和传出的URL组合,如果您遵循路由引擎使用的约定(规则),则不必更改配置。我真的只使用自定义路由的区域或MVC约定之外的任何东西。你所拥有的约定似乎遵循MVC的指导方针,文件夹和控制器相互匹配。所以我不相信你需要一条自定义路线。
ASP.net MVC的路由引擎不提供网页(.cshtml)。它为您的代码中的类处理URL提供了一种方法,可以将text / html呈现给输出流,或者使用Convention以一致的方式解析和提供.cshtml文件。您的View引擎提供了以控制器命名的目录中的网页(.cshtml)文件。这就是说路由引擎控制URL。你试过**return View("NameOfView", Model);**
您需要注意其他事项,例如确保命名空间是正确的,以及您是否从模型中获取字符串?你是否必须正确格式化return View("Message",(object)msg);
而不是return View("Message",msg);
,因为我无法看到你的模型或你的视图,并且没有发布完整的堆栈跟踪很难说为什么你的视图是没有显示。如果你显示一个当然用更改名称调用的URL也会很好。但我能想到的主要是模型和/或命名空间,如果你从视图中调用Layout = "~/Views/Shared/_Layout.cshtml";
或依赖于_ViewStart
文件。还要检查您是否通过菜单或链接调用了正确的操作。 @Html.Action
方法实际调用控制器并呈现视图,您是否尝试使用intellisense查看ActionLink的重载(@Html.ActionLink("Some text","Action","Controller", new {id=1}, null)
),以确保从链接中调用正确的操作。希望这种方式能指向正确的解决方案。