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


i have html number input on page accepts integer value. code follows:

@html.textbox("answer[" + + "].score", null, new { @class = "form-control", type = "number", value="0", id = "answer[" + + "]_score" }) 

in model have defaulted score properties 0 still didn't render 0 in view. used value="0" directly on input still doesn't render 0.

it renders like:

<input class="form-control" id="answer[0]_score" name="answer[0].score" type="number" value=""> 

this problem when go save form, null value sent controller when score isn't nullable form doesn't submit.

is there way 0 default instead of blank value?

use value capital v:

value = "0"  

not

value="0" 

value keyword used in setters. for example.

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

as need set value of "num" (in case answer_++) explicitly in code behind when create object - value not set, empty.

so value not overwritten value of setter.

also have error handling , null checks when passing data through controllers.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -