How to specify MaxLength for a textbox , Like MaxLenth="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
1 Answer
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) %>
2 Comments
Basavaraj Badiger
Thanks for the maxlength.But [DisplayFormat(DataFormatString = "{0:$###,###,###,##0.00}", ApplyFormatInEditMode = true)] public decimal? Value { get; set; } is not working , its not at all formating as desired.
Darin Dimitrov
@Basavaraj, did you use
Html.EditorFor(x => x.Value) in your view instead of Html.TextBoxFor(x => x.Value)? The DisplayFormat attribute applies only when using the EditorFor helper.