Basavaraj Badiger
Basavaraj Badiger

Reputation: 269

FormatString for a TextBoxFor() in Asp.NET MVC

Upvotes: 2

Views: 3116

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

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

Upvotes: 6

Related Questions