I have a class Question with properties like below:
[Required]
public string Subject { get; set; }
[Required]
public string Content { get; set; }
I try to do some server validation. I've included these scripts:
<script src="@Links.Scripts.jquery_validate_min_js" type="text/javascript"></script>
<script src="@Links.Scripts.jquery_validate_unobtrusive_min_js" type="text/javascript"></script>
And this is the "create" view:
<dt><span>Question title*</span>please be specific but brief</dt>
<dd>@Html.TextBoxFor(m => m.Subject, new { @class = "boxsizingBorder" }) @Html.ValidationMessageFor(m=>m.Subject)</dd>
<dt><span>Question details</span></dt>
<dd>@Html.TextAreaFor(m => m.Content, 7, 30, new { @class = "boxsizingBorder" })@Html.ValidationMessageFor(m => m.Content)</dd>
When i try to post a new question like that:
$('#saveChanges').click(function () {
$('#createQuestion').submit();
});
(#saveChanges
is the id of my span and #createQuestion
is the id of my form)
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?
How should Server Validation work in this instance?