【发布时间】:2010-06-09 07:20:48
【问题描述】:
我正在使用此博客中的代码:http://blog.maartenballiauw.be/post/2009/05/20/ASPNET-MVC-Domain-Routing.aspx 来实现子域。我的目标是有一个区域 /admin/ 可以与以下网址一起使用:admin.localhost\test\index 而我的主要应用程序是 localhost\home\index。
我已经实现了以下路线:
context.Routes.Add("AdminDomainRoute", new DomainRoute(
"admin.localhost", // Domain with parameters
"{controller}/{action}/{id}", // URL with parameters
new { controller = "test", action = "index", id = "", isAdmin = true }
// Parameter defaults
));
并且 /Admin 区域有一个名为 TestController 的控制器和一个名为 /Test/Index.aspx 的视图。但是当我尝试访问 admin.localhost(在 \hosts 文件中定义)时,我收到以下错误:
System.InvalidOperationException: The view 'index' or its master was not found. The following locations were searched:
~/Views/test/index.ascx
~/Views/Shared/index.ascx
~/Views/Admin/test/index.ascx
~/Views/test/index.aspx
~/Views/Shared/index.aspx
~/Views/Admin/test/index.aspx
~/Views/test/index
~/Views/Shared/index
~/Views/Admin/test/index
at System.Web.Mvc.ViewResult.FindView(ControllerContext context)
at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.<InvokeActionResultWithFilters>b__11()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass14.<>c__DisplayClass16.<InvokeActionResultWithFilters>b__13()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
视图没有定义母版页。
【问题讨论】:
标签: asp.net-mvc-2 c#-4.0