Asp.net mvc 在ASP.NET MVC中,当使用正确类型的对象呈现页面时,我遇到了错误的类型错误
我正在使用MVC Preview 5开发一个应用程序。我使用了类型化视图 设置debug=“false”后,我发现我接收到表单的错误: “已将模型项传递到 这本字典是打字机 'blah.Models.UserAdmin.IndexData'但是 此词典需要一个模型项 类型 'blah.Models.organizationadmin.IndexData'” 当调试打开时,我没有收到这些错误 看起来MVC框架正在按视图名称缓存视图。如果有两个操作使用相同名称的视图(尽管在不同的名称空间中),我发现只有第一个执行的操作成功,第二个操作总是导致此错误 例如,我有一个UserAdminController和一个OrganizationAdminControllerAsp.net mvc 在ASP.NET MVC中,当使用正确类型的对象呈现页面时,我遇到了错误的类型错误,asp.net-mvc,Asp.net Mvc,我正在使用MVC Preview 5开发一个应用程序。我使用了类型化视图 设置debug=“false”后,我发现我接收到表单的错误: “已将模型项传递到 这本字典是打字机 'blah.Models.UserAdmin.IndexData'但是 此词典需要一个模型项 类型 'blah.Models.organizationadmin.IndexData'” 当调试打开时,我没有收到这些错误 看起来MVC框架正在按视图名称缓存视图。如果有两个操作使用相同名称的视图(尽管在不同的名称空间中),我发现
- 两者都有一个“索引”动作
- 两者都使用名为“Index.aspx”的视图(每个视图包含在控制器的视图文件夹中;Views/UserAdmin/Index.aspx和Views/organizationadmin.Index.aspx)
- 这两个视图都是类型化的,并使用名为IndexData的模型(blah.models.UserAdmin.IndexData和blah.models.organizationadmin.IndexData)
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
InvalidOperationException:传入字典的模型项的类型为“blah.Models.RoleAdmin.IndexData”,但此字典需要“blah.Models.UserAdmin.IndexData”类型的模型项。]
System.Web.Mvc.ViewDataDictionary`1.SetModel(对象值)+231
System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary ViewDataDictionary)+99
System.Web.Mvc.ViewPage`1.SetViewData(ViewDataDictionary viewData)+60
System.Web.Mvc.WebFormView.RenderViewPage(ViewContext上下文,ViewPage页面)+64
System.Web.Mvc.WebFormView.Render(ViewContext,TextWriter)+85
System.Web.Mvc.ViewResult.ExecuteResult(ControllerContext上下文)+206
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ActionResult ActionResult)+19
System.Web.Mvc.c\u DisplayClass12.b\u f()+18
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter筛选器、ResultExecutingContext预文本、Func`1 continuation)+257
System.Web.Mvc.c__显示类14.b__11()+20
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter筛选器、ResultExecutingContext预文本、Func`1 continuation)+257
System.Web.Mvc.c__显示类14.b__11()+20
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ActionResult ActionResult,ILST`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
ProcessRequest(HttpContextBase httpContext)+107
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步骤,布尔值&同步完成)+75
是的,已报告错误。现在最好不要调试,或者修改有问题的代码(抱歉,我想不起在哪里)。我认为您的用户控件和视图具有相同的名称。这个错误让我发疯。正在我的视图顶部指定模型。然而,这该死的东西要求一个不同的模式
原来在一个布局页面中有一个孤立的ModelType引用。它在我的视图中被引用为Layout=“~/Views/\u Layout.vbhtml”您是否找到了解决方法?奇怪的是,尽管这个问题已经过时了,但我们遇到的问题与前面描述的完全相同,只是在MVC3中