views:

58

answers:

2

My MVC application has a form with many fields. When I submit the empty form, some of the field values returned were ,, (two commas).

string value = form[key];     // value is ,,

I was expecting to see an empty string, not 2 commas.

A: 

Turns out the problem was that I had two fields on the form with the same name. MVC must have concatenated the values together comma separated.

PeteShack
It's not something MVC does. It's the way it works.
çağdaş
+1  A: 

When you have multiple fields with the same name the values of the fields will be returned as a comma seperated string. It is mentioned here.

From MSDN:

If your form includes multiple objects with the same name (for example, HTML SELECT tags), the item in the form collection will be a comma-delimited list of all the selected values.

thedugas