Client side validation is not working for me in Ajax.BeginForm
This is my code:
<div id="report">
<div id="projectReport">
<div >
@{
Html.EnableClientValidation();
}
@using (Ajax.BeginForm("AnalyticsDates", new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "reportContent"
}))
{
@Html.LabelFor(m => m.StartDate)
@Html.TextBoxFor(m => m.StartDate, new { id = "start" })
@Html.ValidationMessageFor(model => model.StartDate)
@Html.LabelFor(m => m.EndDate)
@Html.TextBoxFor(m => m.EndDate, new { id = "end" })
@Html.ValidationMessageFor(model => model.EndDate)
<input id="btnsearch" type="submit" value=@Titles.Search class="iconHeader"/>
}
</div>
</div>
<div id="reportContent">
</div>
</div>
And I enabled validation in the web.config page:
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
and added js files as well
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
second issue related to the first one, my action is
[HttpPost]
[Authorize(Roles = "XXXReport")]
public async Task<ActionResult> AnalyticsDates(ReportRequestVM reportRequestVM)
{
if (!ModelState.IsValid)
{
return View("**MainReports**", reportRequestVM);
}
// fill reportRequestVM with data
return View("**PartialReport**", reportRequestVM);
}
If the model is valid I return a partial view and the page looks fine , otherwise I return the main view , with the form , but in this the page renders it self twice. the question is, in case the client validation fails,how to return the main form with the validation errors ?
Any help would be appreciated, 10x Rony