2010-05-10 3 views
0

내 사용자 정의 모델 바인더는asp.net MVC 사용자 정의 모델 바인더는 완벽하게 작동하고있다

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.

소스 오류 아래의 오류

에게 나에게

정보를 제공 시작했다 :

[ArgumentException: An item with the same key has already been added.] System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +51 System.Collections.Generic.Dictionary2.Insert(TKey key, TValue value, Boolean add) +7462172 System.Linq.Enumerable.ToDictionary(IEnumerable1 source, Func2 keySelector, Func2 elementSelector, IEqualityComparer1 comparer) +270 System.Linq.Enumerable.ToDictionary(IEnumerable1 source, Func2 keySelector, IEqualityComparer1 comparer) +102 System.Web.Mvc.ModelBindingContext.get_PropertyMetadata() +157 System.Web.Mvc.DefaultModelBinder.BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor) +158 System.Web.Mvc.DefaultModelBinder.BindProperties(ControllerContext controllerContext, ModelBindingContext bindingContext) +90 System.Web.Mvc.DefaultModelBinder.BindComplexElementalModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Object model) +50 System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +1048 System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +280 PitchPortal.Web.Binders.documentModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) in C:\Users\Bich Vu\Documents\Visual Studio 2008\Projects\PitchPortal\PitchPortal.Web\Binders\DocumentModelBinder.cs:33 System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) +257 System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) +109 System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +314 System.Web.Mvc.Controller.ExecuteCore() +105 System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +39 System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7 System.Web.Mvc.<>c_DisplayClass8.b_4() +34 System.Web.Mvc.Async.<>c_DisplayClass1.b_0() +21 System.Web.Mvc.Async.<>c__DisplayClass81.b__7(IAsyncResult _) +12 System.Web.Mvc.Async.WrappedAsyncResult1.End() +59 System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +44 System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +7 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8677678 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +155

아이디어가 있니? 감사합니다

+0

바인더에서 수행중인 작업의 코드를 게시하십시오. 오류는 스택 추적에있는 것일 가능성이 높습니다. 컬렉션에 항목을 추가하려하지만 해당 항목 (또는 동일한 키가있는 항목)이 이미 있습니다. 이 오류는 컬렉션을 복사 할 때 자주 발생합니다. for 루프에서 컬렉션을 반복하지만 동일한 컬렉션에서 항목을 수정하려고 할 때가 있습니다. – mare

+0

public override object BindModel (ControllerContext controllerContext, ModelBindingContext bindingContext) { HttpRequestBase request = controllerContext.HttpContext.Request; string subject = request.Form.Get ("doc.title"); string key = bindingContext.ModelName; 문서로 var doc = base.BindModel (controllerContext, bindingContext); – mike

+0

faliure는 모델 바인딩 코드에서 매우 일찍 발생합니다. asp.net model bindin은 querystring에서 값을 가져 와서 값을 가져 와서 작업을하고 일종의 사전에 추가합니다. 콜렉션에서는 내장 된 모델 바인딩이이를 수행합니다. 질문은 왜 그것이 동일한 키를 추가하려고 시도하는 것입니까 – mike

답변

1

here을 참조하십시오, 당신은 아마 같은 문제가있어.

그리고 여러 번 같은 질문을하지 마십시오. 그냥 편집 할 수 있습니다.

관련 문제