Error adding item with same key when submit

Asked 2 years ago, Updated 2 years ago, 92 views

I'd like to solve it as soon as possible.

Environment: Asp.Net MVC4 (cshtml)

I would like to post the viewmodel bound to view on submit to the stovetoller.

An item containing the same key has already been added. '/' An application server error occurs.

I don't know what's wrong, so could someone tell me?

@model namespace.ViewModels.SampleViewModel
...omitted...
@using(Html.BeginForm("Index", "Controller Name", FormMethod.Post))
{
    ...omitted...

    <td><input type="submit" value="Registration"/>/td>

}

// Initial View
[HttpGet]
public ActionResult Index (stringdType)
{
    varViewModel=new Sample ViewModel();

    … (all set in ViewModel) …

    return View (ViewModel);
}

// registration
[HttpPost]
public ActionResult Index (sample ViewModel vm)
{
    ...omitted...
}

Thank you for your cooperation.

c# asp.net mvc

2022-09-30 16:42

1 Answers

Sorry, I solved myself.

It seems that the same input tag that was provided for debugging in the view was a duplicate error in the key, value pair set of ModelState.

When I removed the debugs, they successfully POSTed and took over the Viewmodel.

This post is from @user30436I posted it as a community wiki based on the content of the comment .


2022-09-30 16:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.