TRR
TRR

Reputation: 1643

Asp.net MVC Html.TextboxFor title and validation message conflict

I have a Asp.net MVC application(using Razor View) in which i am using Html.Textboxfor for textbox. Below is the code :

@Html.TextBoxFor(m => m.Textbox1, Model.Attributes)

The attributes i am adding for these are

Model.Attributes = new Dictionary<string,object>);                               
Model.Attributes .Add("size", "3");
Model.Attributes .Add("min", 0);
Model.Attributes .Add("max", 100);                               
Model.Attributes .Add("title", "Value");

So when i click on submit i am validating the Textbox and it shows the default title as error message when data outside the specified range is entered. Any way to prevent this from happening and add a custom error message different from title?

Upvotes: 0

Views: 1674

Answers (1)

maxs87
maxs87

Reputation: 2284

im not sure what u try to do but i think u need just use data anotation

 [StringLength(100,  MinimumLength=1, ErrorMessage = "error message here")]
 public string title { get; set; }

Upvotes: 2

Related Questions