开发者

FormatString for a TextBoxFor() in Asp.NET MVC

开发者 https://www.devze.com 2023-02-08 07:15 出处:网络
How to specify MaxLength for a textbox , Like MaxLenth=\"18\" How to Set the TextBox Format String as FormatString=\"$###,###,###,##0.00\"
  • How to specify MaxLength for a textbox , Like MaxLenth="18"

  • How to Set the TextBox Format String as FormatString="$###,###,###,##0.00" in model开发者_如何学Python so even if i enter 100 it should automatically become $100.00


How to specify MaxLength for a textbox , Like MaxLenth="18"

You could pass additional html attributes to the TextBoxFor method:

<%= Html.TextBoxFor(x => x.SomeValue, new { maxlength = "18" })

How to Set the TextBox Format String as FormatString="$###,###,###,##0.00" in model so even if i enter 100 it should automatically become $100.00

You could use the [DisplayFormat] attribute:

[DisplayFormat(DataFormatString = "{0:$###,###,###,##0.00}", ApplyFormatInEditMode = true)]
public decimal? Value { get; set; }

and then:

<%= Html.EditorFor(x => x.Value) %>
0

精彩评论

暂无评论...
验证码 换一张
取 消