Reputation: 5192
I have a MVC3 view, local debug perfectly fine, after I deployed to server I found unobtrusive validation is not fired at all.
I saved the output to a static HTML file and get rid all unnecessary codes and with following section remaining
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
Dummy
</title>
<link type="text/css" href="/Content/site.css" rel="stylesheet" />
<script type="text/javascript" src="/Scripts/jquery-1.6.4.js"></script>
<script type="text/javascript" src="/Scripts/jquery.validate.js"></script>
<script type="text/javascript" src="/Scripts/jquery.validate.unobtrusive.js"></script>
<script type="text/javascript" src="/Scripts/jquery.unobtrusive-ajax.js"></script>
</head>
<body>
<form action="/Test/Dummy" data-ajax="true" data-ajax-complete="MyDummy.OnComplete" data-ajax-method="Post" id="form0" method="post">
<select data-val="true" data-val-number="The field SourceId must be a number." data-val-required="SourceId required." id="SourceId" name="SourceId"></select>
<span class="field-validation-valid" data-valmsg-for="SourceId" data-valmsg-replace="true"></span><br />
<select data-val="true" data-val-number="The field DestinationId must be a number." data-val-required="DestinationId required." id="DestinationId" name="DestinationId"></select>
<span class="field-validation-valid" data-valmsg-for="DestinationId" data-valmsg-replace="true"></span><br />
<input type="submit" value=" Submit " class="ButtonStyle" />
</form>
<script type="text/javascript">
var MyDummy = {
OnComplete: function (content) {
alert(content.responseText);
}
}
</script>
</body>
</html>
I believe I have included proper JavaScript files, all the rendered Html looks fine to me. When I click on the submit button I expect validation message, but instead the oncomplete event fires.
I am very lost here, anybody has clue what is wrong?
Edit 1, I copied the same static Html file to my local project's folder and access it via http://localhost:48194/test.htm (my local ASP.NET Development Server) and everything works fine. But if I load the same file from 2008 server's local IE8 at http://localhost:87/test.htm (IIS 7) then I got the issue. Somehow it leads me to think is there something wrong setting IIS7 which blocks or partially blocks the access to JavaScript files properly?
Edit 2, If I change the JS reference to use CDN like
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.4.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.validate.unobtrusive.js"></script>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/mvc/3.0/jquery.unobtrusive-ajax.js"></script>
Then it works. I really don't know now what IIS7 could do to damage the local JS file transportation.
Upvotes: 0
Views: 1242
Reputation: 231
@section Scripts
{
<script src="../Scripts/jquery.validate-vsdoc.js"></script>
<script src="../Scripts/jquery.validate.js"></script>
<script src="../Scripts/jquery.validate.min.js"></script>
<script src="../Scripts/jquery.validate.unobtrusive.js"></script>
<script src="../Scripts/jquery.validate.unobtrusive.min.js"></script>
}
Upvotes: 0
Reputation: 8758
I does sound like IIS blocks the javascript.
In IIS you can set filters for which files are allowed or denied. Maybe for some reason someone (accidentally) blocked .js? - Another issue could be file access. IIS normally runs under a different user, so maybe it does not have access?
But I'm kind of just guessing. So the easiest way to test this is to just visit the .js file directly. So just open your http://localhost:87/Scripts/jquery-1.6.4.js
and check what IIS returns. Maybe it returns a 403 error, maybe something else, at least it'll probably help to figure out what's wrong.
Upvotes: 1