简体   繁体   English

剃刀文本框值中的前缀0

[英]Prefix 0 in Razor Textbox value

Here is my Razor text box 这是我的剃刀文本框

@Html.TextBoxFor(model => model.ShortBufferHour,new { @maxlength = "2",Style="text-align:center;"})

It shows the Hours as 7 . 它显示Hours7 How to prefix a 0 in case of single digit hour. 如果是个位数小时,如何给0加上前缀。 So that the textbox content be 07 使文本框内容为07

You need to use the D2 format option and pass the value through as an html atttribute: 您需要使用D2格式选项,并将值作为html属性传递给:

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) })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM