I have the problems with pass list of string into controller in mvc 3 Razor
I use Jquery to set value.
But in the server side the first value always false, I don’t know why 🙁
Here my code:
Class:
public class ListFieldInfo
{
public List<string> FieldFilters { get; set; }
}
View:
@using (Html.BeginForm("Export", "Books", FormMethod.Post,new { @id = "exportForm", hidden = true }))
{
<fieldset>
@Html.HiddenFor(m => m.status_info.FieldFilters, new { @id = "status_filters" })
</fieldset>
}
Javascript:
$('#status_filters').add("0");
$('#status_filters').add("1");
Debug in controller:
FieldFilters[0] = "false"// I don't know why
FieldFilters[1] = "1"
I tried to search google and stackoverflow but still no help
Please help me, thank in advance
In your case you need to receive single string for one HiddenField and split it on the server side.
If you need to receive List you need to build set of controls with names like:
Here is great article from Phill Haak: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx