Reputation: 3138
So I have a view similar to this:
...
<input type="text" id="FieldOne" />
<input type="text" id="FieldTwo" />
<input type="text" id="FieldThree" />
...
That mimics this class:
public class Foo{
public string FieldOne { get; set; }
public string FieldTwo { get; set; }
public string FieldThree { get; set; }
}
And an action in the corresponding controller:
[HttpPost]
public ActionResult View(Foo param)
{
...
}
When I submit the form, the parameter "param" in the Post action properly copies the values of all the fields that match the class, except for one of them (say, FieldOne). These inputs are generated by Html.TextboxFor().
Is this a idiosyncratic problem or is there something I may be forgetting about?
Upvotes: 1
Views: 620
Reputation: 8393
Your input boxes are not valid. They should look as follows:
// Start Form
<input type="text" id="FieldOne" name="FieldOne" />
<input type="text" id="FieldTwo" name="FieldTwo" />
<input type="text" id="FieldThree" name="FieldThree" />
// End Form
With that said is there any reason why you are not using the Html Helpers? Given your model it would be better to write your form as follows:
// Start Form
@Html.TextBoxFor(m => m.FieldOne)
@Html.TextBoxFor(m => m.FieldTwo)
@Html.TextBoxFor(m => m.FieldThree)
// End Form
Upvotes: 6