Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 在ASP.NET MVC中,当使用正确类型的对象呈现页面时,我遇到了错误的类型错误_Asp.net Mvc - Fatal编程技术网

Asp.net mvc 在ASP.NET MVC中,当使用正确类型的对象呈现页面时,我遇到了错误的类型错误

Asp.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框架正在按视图名称缓存视图。如果有两个操作使用相同名称的视图(尽管在不同的名称空间中),我发现

我正在使用MVC Preview 5开发一个应用程序。我使用了类型化视图

设置debug=“false”后,我发现我接收到表单的错误:

“已将模型项传递到 这本字典是打字机 'blah.Models.UserAdmin.IndexData'但是 此词典需要一个模型项 类型 'blah.Models.organizationadmin.IndexData'”

当调试打开时,我没有收到这些错误

看起来MVC框架正在按视图名称缓存视图。如果有两个操作使用相同名称的视图(尽管在不同的名称空间中),我发现只有第一个执行的操作成功,第二个操作总是导致此错误

例如,我有一个UserAdminController和一个OrganizationAdminController

  • 两者都有一个“索引”动作

  • 两者都使用名为“Index.aspx”的视图(每个视图包含在控制器的视图文件夹中;Views/UserAdmin/Index.aspx和Views/organizationadmin.Index.aspx)

  • 这两个视图都是类型化的,并使用名为IndexData的模型(blah.models.UserAdmin.IndexData和blah.models.organizationadmin.IndexData)

如果我先访问OrganizationAdmin/Index,我会发现任何后续查看UserAdmin/Index的尝试都会导致上面显示的错误消息

相反,如果我先访问UserAdmin/Index(在重新启动应用程序之后),我会发现导航到OrganizationAdmin/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
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中