Note that there are some explanatory texts on larger screens.

plurals
  1. POServer validation doesn't work when i post via jquery
    text
    copied!<p>I have a class Question with properties like below:</p> <pre><code>[Required] public string Subject { get; set; } [Required] public string Content { get; set; } </code></pre> <p>I try to do some server validation. I've included these scripts:</p> <pre><code>&lt;script src="@Links.Scripts.jquery_validate_min_js" type="text/javascript"&gt;&lt;/script&gt; &lt;script src="@Links.Scripts.jquery_validate_unobtrusive_min_js" type="text/javascript"&gt;&lt;/script&gt; </code></pre> <p>And this is the "create" view:</p> <pre><code>&lt;dt&gt;&lt;span&gt;Question title*&lt;/span&gt;please be specific but brief&lt;/dt&gt; &lt;dd&gt;@Html.TextBoxFor(m =&gt; m.Subject, new { @class = "boxsizingBorder" }) @Html.ValidationMessageFor(m=&gt;m.Subject)&lt;/dd&gt; &lt;dt&gt;&lt;span&gt;Question details&lt;/span&gt;&lt;/dt&gt; &lt;dd&gt;@Html.TextAreaFor(m =&gt; m.Content, 7, 30, new { @class = "boxsizingBorder" })@Html.ValidationMessageFor(m =&gt; m.Content)&lt;/dd&gt; </code></pre> <p>When i try to post a new question like that:</p> <pre><code>$('#saveChanges').click(function () { $('#createQuestion').submit(); }); </code></pre> <p>(<code>#saveChanges</code> is the id of my span and <code>#createQuestion</code> is the id of my form)</p> <p>If I don't fill in the example Subject field I momentarily see an error message (field is required, etc.) but question is posted anyway. Is this happening because I'm trying to post the form using jQuery or what?</p> <p>How should Server Validation work in this instance?</p>
 

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