Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Can we show validation message differently in MVC3

Can we show validation message differently in MVC3

Scheduled Pinned Locked Moved ASP.NET
htmlcomquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jagz W
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • J Jagz W

      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

      A Offline
      A Offline
      Anurag Gandhi
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups