开发者

Action Parameter POST .. An item with the same key has already been added

开发者 https://www.devze.com 2022-12-21 16:26 出处:网络
I have a little problem in ASP.NET MVC 2 FrameWork 4... Let me explain : I have one class that contains other classes like ...

I have a little problem in ASP.NET MVC 2 FrameWork 4... Let me explain :

I have one class that contains other classes like ...

IndexViewData -­­> MemberViewData -> UserViewData

public class IndexViewData : Manager
{
    public MemberViewData member { get; set; }
    ....

public class MemberViewData : Manager
{
    public UserViewData user { get; set; }
    ....

In my page Inscription all my values in the form represent a property in one of these classes.

<% using (Html.BeginForm("Index", "Home", FormMethod.Post, new { @name = "frm_inscription", @id = "frm_inscription" })) { %>
            <p><label>Courriel : </label><input type="text" name="username" value="<%= Model.membe开发者_如何转开发r.user.userName %>" /></p>
            <p><label>Nouveau mot de passe : </label><input type="password" name="password"/> </p>
            <p><label>Confirmer : </label><input type="password" name="confirmpassword" /> </p>
            <p><label>Votre ville : </label><%= Html.DropDownList("cityid", DDL.ddlCities(Model.member.cityId)) %></p>
            <p><label>Votre région : </label><%= Html.DropDownList("regionid", DDL.ddlRegions(Model.member.regionId)) %></p>
.....
<% } %>

My page Inscription are strongly typed IndexViewData

When I want to received the postback of the form I'm forced to declare the function like this ..

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(IndexViewData view, MemberViewData member, UserViewData user)
{
  member.user = user
  view.member = member

 ...
}

because MVC cannot go deep in my object to fill the information of the value form of my member and my user ... and .. because I declare twice (in IndexViewData he have an propertie of type MemberViewData) in IndexViewData and in my function they give me this error :

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) +52    System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
+9549131    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) +603    System.Web.Mvc.DefaultModelBinder.BindComplexModel(ControllerContext controllerContext, ModelBindingContext bindingContext) +2502    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()
+8771193    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
+184

I put everything in comments to finaly get to that conclusion .. when I renamed properties or rename the value of the field name in a input tag. It works! But I dont want to rename them to keep my code standard and for more flexiblity

0

精彩评论

暂无评论...
验证码 换一张
取 消