This is probably a dummy question, but I'm stuck with a problem I can't resolve by myself.
I'm working on an ASP.NET MVC3 project. For some reason, on a particular Create page, a decimal field is not binded on the model when the page is validated and I can't understand why.
Here is my code :
@model ModelA
/*some TextBoxFor or others DropDownListFor, all of them working well*/
@Html.TextBoxFor(m => m.ModelB.ModelC.MyField, new { @id = "txtMyField" })
When I validate the page, the model ModelA is correctly filled EXCEPT for this particular field MyField. Others fields are OK, for exemple :
@Html.TextBoxFor(m => m.ModelB.AnotherField, new { @id = "txtAnotherField" })
perfecly works, and others properties of ModelB are correctly filled.
My models
ModelA contains a property of type ModelB called ModelB.
ModelB contains a property of type ModelC called ModelC.
ModelC contains a property called MyField. (I'll probably add one or two more in the future). This field is a decimal field, without any DataAnnotation or anything.
public decimal MyField { get; set; }
By the way, when in my browser's console I request
$('#txtMyField').val()
it displays the good value, for example 12.54.
What I tried
- Change this decimal field to a float type, the problem is the same.
- Put it in an EditorFor instead of a TextBoxFor, the problem is the same.
- Put the field MyField in ModelB. The only ModelB's property to 0 is MyField.
Why is this field a rebel ? I probably do something wrong, but I can't understand where... Can someone explain me where is my mistake ?
Thank you !