0

I have two different views belonging to two different controllers. A view the first controller works fine with unobtrusive validation. The 2nd view does not. It seems like validation plugin is not running because $.validator.unobtrusive is undefined.

In the shared _layout file I have the following script tags:

<script src="@Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.19.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>

so why is the 2nd view not working with unobtrusive validation?

Update

In both cases I am loading the forms via Ajax calls. I have verified the the main page with the broken validation can support unobtrusive validation for non-ajax loaded forms.

Update2

I finally got it working, but it's not a permanent fix yet. The source of the problem is an editable Telerik MVC Grid on the same page. It's somehow deleting/preventing the $.validator.unobtrusive from being used in my ajax loads.

Alex
  • 9,250
  • 11
  • 70
  • 81

1 Answers1

1

I don't know if this will make a difference or not, but are you able to change each line to the following?

<script src="@Url.Content('~/Scripts/jquery-1.7.2.min.js')" type="text/javascript"></script>
<script src="@Url.Content('~/Scripts/jquery-ui-1.8.19.min.js')" type="text/javascript"></script>
<script src="@Url.Content('~/Scripts/jquery.validate.min.js')" type="text/javascript"></script>
<script src="@Url.Content('~/Scripts/jquery.validate.unobtrusive.min.js')" type="text/javascript"></script>
<script src="@Url.Content('~/Scripts/jquery.unobtrusive-ajax.min.js')" type="text/javascript"></script>

This is a very MINOR change, but the "s in @Url.Contents() have been changed to 's. The quotes may be getting crossed at some point.

Chase
  • 29,019
  • 1
  • 49
  • 48
  • I used your suggesting but swapped the single quotes to be on the outside since I want to use double quotes inside for the .net string. The problem remains – Alex May 08 '12 at 13:04
  • Have you looked at the answer for this similar question? http://stackoverflow.com/questions/9321040/unobtrusive-validation-on-dynamically-added-partial-view-not-working – Chase May 08 '12 at 15:56
  • That doesn't help me because `$.validator.unobtrusive` is undefined – Alex May 08 '12 at 16:47
  • I believe I may need to see more code to help further, but I did find another posting discussing the undefined issue here: http://stackoverflow.com/questions/6103160/unobtrusive-client-validation-in-partial-views ...Hope it helps! – Chase May 08 '12 at 16:53
  • Yeah, I saw that before. The first thing in the source of that function is `$.validator.unobtrusive.parse(selector);` so I don't think that will work. – Alex May 08 '12 at 17:34
  • I've added comments to the original post that pinpoint the root of the problem. – Alex May 08 '12 at 20:25