Input with default value set to 0 is being rendered without the 0

Viewed 2813

I have a HTML number input on my page that accepts an integer value. The code is as follows:

@Html.TextBox("Answer[" + i + "].Score", null, new { @class = "form-control", type = "number", value="0", id = "Answer[" + i + "]_Score" })

In my model I have defaulted all the Score properties to 0 but it still didn't render with a 0 in the view. I then used value="0" directly on the input but it still doesn't render the 0.

It renders like:

<input class="form-control" id="Answer[0]_Score" name="Answer[0].Score" type="number" value="">

This is only a problem when I go to save the form, a null value is sent to the controller when score isn't nullable so the form doesn't submit.

Is there any way to get that 0 to be the default instead of a blank value?

2 Answers
Related