MVC2中出现一个相同的键已被添加的问题原因
来源:互联网 发布:淘宝花费总额查询 编辑:程序博客网 时间:2024/05/16 10:24
这两天用MVC2搞了一个软件,结果今天调试时碰到一个很头疼的问题。
只要使用HtmlHelper的控件模版在界面上显示控件,如下:
就报出An item with the same key has already been added这个错误。
后来在国外网站上才查到一个老兄也碰到这个问题,原因是对应的实体中有重名的属性。
像我这里 UserInfo实体类中有一个"ID"属性,这个实体类继承自EntityBase类,基类中有一个属性"Id".
注意这里的两个属性大小写不同,C#会认为是两个属性,但是在MVC的Request.Form中Key值是不区分大小写的。
这样就会出现添加重复键值的错误。
这个错误很少发生,因为如果大小写相同它也会被认为是一个属性,只有大小写不同时才会发生。
An item with the same key has already been added.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.ArgumentException: An item with the same key has already been added.
Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace: [ArgumentException: An item with the same key has already been added.] System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52 System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +9383019 System.Linq.Enumerable.ToDictionary(IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) +252 System.Linq.Enumerable.ToDictionary(IEnumerable`1 source, Func`2 keySelector, IEqualityComparer`1 comparer) +91 System.Web.Mvc.ModelBindingContext.get_PropertyMetadata() +228 System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +392 System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) +147 System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Object model) +98 System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +2503 System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +548 System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +474 System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +181 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830 System.Web.Mvc.Controller.ExecuteCore() +136 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +111 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39 System.Web.Mvc.<>c__DisplayClass8.<BeginProcessRequest>b__4() +65 System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44 System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +42 System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54 System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +52 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8836977 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
- MVC2中出现一个相同的键已被添加的问题原因
- 代码中出现的奇怪问题原因
- 解决MVC2里不能使用相同Action名字的问题(与HttpVerbs无关)
- NoClassDefFoundError出现的一个原因
- QT中添加Q_OBJECT出现的问题
- QT中添加Q_OBJECT出现的问题
- QT中添加Q_OBJECT出现的问题
- QT中添加Q_OBJECT出现的问题
- 终端呼叫中出现颤音的一个原因
- Java中出现了一个不知原因的NullPointerException
- MySQL中两个表字段名相同导致的一个问题
- Set中添加相同的元素
- 程序执行修改,添加,删除时出现程序停止的问题----原因事务问题
- eclipse使用中出现的一个问题
- 解决myeclipse中出现的一个问题
- TC 使用中出现的一个问题
- 在asp.net mvc2中添加Area及相关的路由定义
- 求一个字符串中出现相同且长度最长的字符串
- extjs 中store 关于baseParams的一个bug
- 命中测试和SendMessage WM_NCLBUTTONDOWN对鼠标消息的影响
- 正则表达式规则,正则表达式详解
- C/C++开发常用工具及系统编程
- GridView控件中模板列CheckBox全选、反选、取消
- MVC2中出现一个相同的键已被添加的问题原因
- 分享我最新收藏的桌面主题资源07-28整理分享!
- MEF程序设计指南七:使用目录(Catalog)动态装载xap与目录筛选(Filtered Catalog)
- 最新Win7主题破解补丁07-28下载
- 【转】创业者最容易被忽悠的五大方面
- Solaris
- SQL语句优化工具LECCO SQL Expert
- 安家第一篇
- 举例说明同步通信与异步通信