Can we show validation message differently in MVC3
-
Hi all, I have textbox with of email. It has two validation one is required and another is regularexpression. Can i show different message for the both validation? e.g This is validation logic [Required(ErrorMessage = "*")] [DataType(DataType.EmailAddress)] [RegularExpression("^[\\w-]+(\\.[\\w-]+)*@([a-z0-9-]+(\\.[a-z0-9-]+)*?\\.[a-z]{2,6}|(\\d{1,3}\\.){3}\\d{1,3})(:\\d{4})?$", ErrorMessage = "Email address should be in proper format (e.g. username@domain.com)")] public String Email { get; set; } Below is html <div class="input_set"> <div class="editor-label"> @Html.LabelFor(model => model.Email) </div> <div class="editor-field"> @Html.TextBoxFor(model => model.Email) <br /> @Html.ValidationMessageFor(model => model.Email) </div> </div> Now i wnat to show @Html.ValidationMessageFor(model => model.Email) message in different location. One person's data is another person's program. --J.Walia
-
Hi all, I have textbox with of email. It has two validation one is required and another is regularexpression. Can i show different message for the both validation? e.g This is validation logic [Required(ErrorMessage = "*")] [DataType(DataType.EmailAddress)] [RegularExpression("^[\\w-]+(\\.[\\w-]+)*@([a-z0-9-]+(\\.[a-z0-9-]+)*?\\.[a-z]{2,6}|(\\d{1,3}\\.){3}\\d{1,3})(:\\d{4})?$", ErrorMessage = "Email address should be in proper format (e.g. username@domain.com)")] public String Email { get; set; } Below is html <div class="input_set"> <div class="editor-label"> @Html.LabelFor(model => model.Email) </div> <div class="editor-field"> @Html.TextBoxFor(model => model.Email) <br /> @Html.ValidationMessageFor(model => model.Email) </div> </div> Now i wnat to show @Html.ValidationMessageFor(model => model.Email) message in different location. One person's data is another person's program. --J.Walia
First of all, use pre tag to format your code. You have a very limited control on ValidationMessage and ValidationSummary of DataAnnotation. If you wish to customize it further, i would suggest to go for JQuery/Javascript validation.
Anurag Gandhi.
http://www.gandhisoft.com
Life is a computer program and every one is the programmer of his own life.
My latest article: Group GridView Data