An input with a default value of 0 is displayed without 0

I have an HTML code number on my page that takes 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 set all properties Scoreto 0 by default , but it still did not display from 0 in the view. Then I used value="0"directly at the input, but it still does not display 0.

It displays:

<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 the evaluation is not null, so the form is not submitted.

Is there a way to get this default value 0 instead of an empty value?

+4
source share
2

V:

Value = "0" 

value="0"

value - , . .

private int num;
public virtual int Number
{
    get { return num; }
    set { num = value; }
}

"num" ( " _ ++" ) , , - , .

, value .

.

+5

, 'v' . :

    Value = "0" 
+2

Source: https://habr.com/ru/post/1682210/


All Articles