我正在使用MVC Preview 5开发一个应用程序.我使用了类型化的视图.
设置debug ="false"后,我发现我收到了表单错误:
"传递到字典中的模型项的类型为'blah.Models.UserAdmin.IndexData',但此字典需要类型为'blah.Models.OrganisationAdmin.IndexData'的模型项".
调试打开时,我没有收到这些错误.
看起来MVC框架是按视图名称缓存视图.如果我有两个使用相同名称的视图的操作(虽然在不同的命名空间中),我发现只有先执行的操作成功,第二个总是导致此错误.
例如,我有一个UserAdminController和一个OrganisationAdminController.
两者都有"索引"动作.
两者都使用名为'Index.aspx'的视图(每个视图都包含在控制器的视图文件夹中; Views/UserAdmin/Index.aspx和Views/OrganisationAdmin.Index.aspx).
两个视图都是类型化的,并使用名为IndexData的模型(blah.Models.UserAdmin.IndexData和blah.Models.OrganisationAdmin.IndexData)
如果我首先访问OrganisationAdmin/Index,我发现任何后续查看UserAdmin/Index的尝试都会导致上面显示的错误消息.
相反,如果我首先访问UserAdmin/Index(重新启动应用程序后),我发现导航到OrganisationAdmin/Index会导致等效错误(反之类型).
我重命名了我的一个观点"UserAdminIndex.aspx",这似乎解决了这个问题.但是,这不应该是一个问题.当然MVC框架支持类似命名的视图?我错过了什么?
任何帮助感激不尽.
沙
请注意,我已经看到了一个问题"在ASP.NET MVC中,我在使用正确的类型化对象呈现用户控件时遇到了错误的类型错误".我遇到了类似的问题,但我没有使用RenderUserControl().
堆栈跟踪:
InvalidOperationException: The model item passed into the dictionary is of type 'blah.Models.RoleAdmin.IndexData' but this dictionary requires a model item of type 'blah.Models.UserAdmin.IndexData'.]
System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) +231
System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary viewDataDictionary) +99
System.Web.Mvc.ViewPage`1.SetViewData(ViewDataDictionary viewData) +60
System.Web.Mvc.WebFormView.RenderViewPage(ViewContext context, ViewPage page) +64
System.Web.Mvc.WebFormView.Render(ViewContext viewContext, TextWriter writer) +85
System.Web.Mvc.ViewResult.ExecuteResult(ControllerContext context) +206
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ActionResult actionResult) +19
System.Web.Mvc.<>c__DisplayClass12.<InvokeActionResultWithFilters>b__f() +18
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +257
System.Web.Mvc.<>c__DisplayClass14.<InvokeActionResultWithFilters>b__11() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +257
System.Web.Mvc.<>c__DisplayClass14.<InvokeActionResultWithFilters>b__11() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ActionResult actionResult, IList`1 filters) +188
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +386
System.Web.Mvc.Controller.ExecuteCore() +112
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +23
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +107
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +39
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3949 次 |
| 最近记录: |