Default value for TextBoxFor in ASP.NET MVC

前端 未结 6 1722
我寻月下人不归
我寻月下人不归 2021-01-13 09:04

In ASP.NET MVC, I wrote below code to give the textbox a initial value:

@Html.TextBoxFor(p => p.WEIGHT, new { tabindex = \"140\", 
                                


        
6条回答
  •  耶瑟儿~
    2021-01-13 09:41

    Use TextBox instead of TextBoxFor

    @Html.TextBox("WEIGHT", Model.WEIGHT ?? "0", new {...})
    

    or if WEIGHT is an empty string

    @Html.TextBox("WEIGHT", Model.WEIGHT == "" ? "0" : Model.WEIGHT, new {...})
    

提交回复
热议问题