Is POSTing a Dictionary to an .NET MVC action possible?

Posted by Brenton Alker on Stack Overflow See other posts from Stack Overflow or by Brenton Alker
Published on 2010-04-19T23:24:30Z Indexed on 2010/04/19 23:33 UTC
Read the original article Hit count: 330

Filed under:
|
|

I have a form which contains a series of fields like:

<input type="text" name="User[123]" value="Alice" />
<input type="text" name="User[456]" value="Bob" />
...

Where the index of the User array (123 and 456) are ID's associated with the value. I'm trying to update these values in the controller. My thinking is that a Dictionary that maps ID to name would work, but creating the action like:

public void Save(Dictionary<string, string> user) {
    // ...
}

results in the user parameter being null.

So, is passing a Dictionary possible? or, is there another method to achieve this?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about ASP.NET