Here is my Razor text box
@Html.TextBoxFor(model => model.ShortBufferHour,new { @maxlength = "2",Style="text-align:center;"})
It shows the Hours
as 7
. How to prefix a 0
in case of single digit hour. So that the textbox content be 07
You need to use the D2
format option and pass the value through as an html atttribute:
This can be done as follows:
@Html.TextBoxFor(model => model.ShortBufferHour, new { @maxlength = "2",Style="text-align:center;", Value=String.Format("{0:D2}",Model.ShortBufferHour) })
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.