Reputation: 11
How do I avoid postback for validation when I press Submit? When pressing submit, the page reload/postback and THEN it gives me the validation error.
@model X.Models.ModelVm
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Birthday, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Birthday, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Birthday, "", new { @class = "text-danger" })
</div>
</div>
.....
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Get data" class="btn btn-default"/>
</div>
</div>
</div>
}
My ViewModel:
[Required]
[DataType(DataType.DateTime)]
public DateTime Birthday { get; set; }
Upvotes: 0
Views: 984
Reputation: 126
ClientValidationEnabled
and UnobtrusiveJavaScriptEnabled
.jquery
, jquery.validate.js
, jquery.validate.unobtrusive.js
in Your view.Upvotes: 2