Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get the value of Validation Message from form in ASP.Net MVC, using javascript?
    primarykey
    data
    text
    <p>Hy,</p> <p>In my ASP.NET MVC application in the aspx page I set </p> <pre><code>&lt;% Html.EnableClientValidation(); %&gt; </code></pre> <p>to enable client validation on my form. So, for my input I have this code to declare the texbox for email and it's validation </p> <pre><code>&lt;%: Html.TextBoxFor(model =&gt; model.Email)%&gt; &lt;%: Html.ValidationMessageFor(model =&gt; model.Email)%&gt; &lt;%: Html.ValidationSummary(true)%&gt; </code></pre> <p>In the model I declare the email property like:</p> <pre><code> [Required(ErrorMessage = "Required email")] [DisplayName("Email *")] [RegularExpression("^[a-z0-9+\\+-]+(\\.[a-z0-9+\\+-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*\\.([a-z]{2,4})$", ErrorMessage = "Invalid email.")] public string Email { get; set; } </code></pre> <p>The question is, how can I get (using client script) the value of the error message when it's displayed on the page? </p> <p>So when I press some button I can see if the form is valid or not and after that I can display a loading gif.</p> <p>Thanks a lot.</p> <p>Jeff</p> <p><strong>Update</strong></p> <p>HTML source code:</p> <pre><code>&lt;tr&gt; &lt;td class="editor-field"&gt; &lt;input id="Email" name="Email" type="text" value="" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td class="editor-field-validation"&gt; &lt;span class="field-validation-valid" id="Email_validationMessage"&gt;&lt;/span&gt; &lt;div class="validation-summary-valid" id="validationSummary"&gt;&lt;ul&gt;&lt;li style="display:none"&gt;&lt;/li&gt; &lt;/ul&gt;&lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload