I have a main view which has master layout contains all javascripts, ie jQuery DatePicker control, etc.
Inside this main view, I use Ajax.BeginForm(.....) which contains a partial view. And in my controller, if validation fails it returns that partial view. (also the UpdateTargetId in Ajax has been set the Id of the section contains that partial view.)
My error bullets display correctly. However I found I seems to loose the javascript after that. For example my calender/date picker stops working and it comes a normal input box.
What could be the reason?
Thanks a lot!!
Here is the code:
My main view contains one Ajax form. And inside there are 2 partial views. The 2nd one has datepicker inputs.
@using (Ajax.BeginForm("ActionXXX", "ControllerYYY", new AjaxOptions
{
HttpMethod = "POST",
UpdateTargetId = "main"
}))
{
<section id="main" class="....." data-section="....." data-step="">
@Html.Partial("ValidationSummary")
@Html.Partial("SharedPartialView", Model, new ViewDataDictionary {.....})
</section>
}
And JS is included in master file. (Main view has Layout for this)
<script type="text/javascript">
$('input.date').watermark('dd/mm/yyyy');
$('input.date').datepicker({
dateFormat: "dd/mm/yy",
maxDate: 0,
onClose: function () { $(this).valid(); }
});
$('input.time').watermark('hh:mm');
$('input.time').timeEntry();
</script>
The controller is just: when validation fails, return partial view ("SharedPartialView")
if (Request.IsAjaxRequest())
return PartialView("SharedPartialView", ciShareModel); //model
These datepicker and watermark jquery do work when page initially loaded....