Reputation: 13079
I am using the Select2 plugin.
I know that in multiple mode the selected values should come as a comma seperated string, but instead I only get the first value.
Html:
<form action="~/Home/SendData">
<select multiple id="selectElement" name="Data">
<option value="Val1">Val1</option>
<option value="Val2">Val2</option>
</select>
<button type="submit">send</button>
</form>
Javascript:
$(function () {
$("#selectElement").select2();
});
Controller:
public ActionResult SendData(string data)
{
//data contains only val1.
return View();
}
Fiddler:
Upvotes: 1
Views: 918
Reputation: 471
in your case, model binder cannot create string array of values, please, fix your action like this:
public ActionResult SendData(string[] data)
{
return View();
}
Upvotes: 2