1


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

2 Answers 2

2

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:

<input type="hidden" name="model.status_info.FieldFilters" />
<input type="hidden" name="model.status_info.FieldFilters" />
etc...

Here is great article from Phill Haak: http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx

Sign up to request clarification or add additional context in comments.

Comments

0

In a javascript console, try the following:

"0" == false

Helpful, eh? I suspect MVC Is playing silly beggars, assuming that's what you meant. First, try inspecting the POST request in the net panel of Firebug (or whatever web debugging you use), then I'd suggest you try using plain numbers instead of strings.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.