小编f78*_*d23的帖子

传递到字典中的模型项是类型的,但是dicitonary需要类型的模型项

我是ASP.NET MVC的初学者,我有一个相当奇怪的问题,我似乎无法解决如何修复.我通过谷歌找到了同一问题的各种版本的多种解决方案,但它们似乎与我的问题无关.如果有人能够帮助我发现错误,我将不胜感激.

编辑:我知道将@model app.Models.Authentication更改为@model app.Models.ContactMessage将修复它,但我不明白为什么,显然提出的修复将给我一些与表单相关的其他错误.

我的错误:传入字典的模型项的类型为"app.Models.Auth",但此字典需要"app.Models.ContactMessage"类型的模型项

相关问答: 类似问题#1 类似问题#2

堆栈跟踪:

[InvalidOperationException: The model item passed into the dictionary is of type 'app.Models.Authentication', but this dictionary requires a model item of type 'app.Models.ContactMessage'.]
System.Web.Mvc.ViewDataDictionary`1.SetModel(Object value) +378
System.Web.Mvc.ViewDataDictionary.set_Model(Object value) +47
System.Web.Mvc.ViewDataDictionary..ctor(ViewDataDictionary dictionary) +259
System.Web.Mvc.ViewDataDictionary`1..ctor(ViewDataDictionary viewDataDictionary) +37
System.Web.Mvc.WebViewPage`1.SetViewData(ViewDataDictionary viewData) +98
System.Web.Mvc.WebViewPage.set_ViewData(ViewDataDictionary value) +39
System.Web.Mvc.WebViewPage.ConfigurePage(WebPageBase parentPage) +267
System.Web.WebPages.<>c__DisplayClass3.<RenderPageCore>b__2(TextWriter writer) +318
System.Web.WebPages.HelperResult.WriteTo(TextWriter writer) +42
System.Web.WebPages.WebPageExecutingBase.WriteTo(TextWriter writer, HelperResult content) +45
System.Web.WebPages.WebPageBase.Write(HelperResult result) +53
System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body) +178
System.Web.WebPages.WebPageBase.PopContext() +229
System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc

1
推荐指数
1
解决办法
3346
查看次数

标签 统计

asp.net-mvc ×1