0

When the following code is retrieved via an ajax call no validators are written into the view. Any number of these partial views might be added to the page and the textbox gets a datepicker, so that's why the unique id is generated. I certainly appreciate any help.vie

@using Nautilus.Core.Model.Enumeration
@using Nautilus.Web.Models
@using Nautilus.Web.Views.Tools
@model IntensityHistoryModel

<tr>
    <td class='removeIntensityScore' title='Click to remove this item.'></td>
    <td>
        <span></span>
    </td>
    <td>
        @Html.ValidationMessageFor(m => m.IntensityDateGUID)
        @Html.TextBoxFor(m => m.IntensityDate, new { id = Model.IntensityDateGUID, @class = "intensityScoreDate", style = "width:120px" })
    </td>
    <td>
        @Html.DropDownList("IntensityScore", ViewHelper.GetSelectListWithDescriptionFromEnum<IntensityScore.Values>("", new[] { "0" }), " -- Select -- ", new { style = "width:150px;margin:0" })
    </td>
</tr>
Keith Myers
  • 1,379
  • 2
  • 15
  • 29
  • I spoke too soon on the acceptance... the accepted answer does indeed write the validators into the page but still not firing. I tried the suggestion from Iridio with no luck. – Keith Myers Jul 18 '12 at 23:01
  • I found the answer to this in another post:$("form").removeData("validator"); $("form").removeData("unobtrusiveValidation"); $.validator.unobtrusive.parse("form"); – Keith Myers Jul 18 '12 at 23:08

2 Answers2

1

When you do the ajax call, in the callback function you have to call again the validation.

Something like that

$("#myDiv").load($("#myA").attr("href"), function () {
        $.validator.unobtrusive.parse("#myFormPartial");
});
Iridio
  • 9,213
  • 4
  • 49
  • 71
0

It's not including the validation data attributes because the elements are not in a form. The workaround is to initialize a FormContext for your partial view:

@{
    ViewContext.FormContext = new FormContext();
}

<tr><!-- your partial content --></tr>
jrummell
  • 42,637
  • 17
  • 112
  • 171