embed MVC script block in jQuery
I am trying to mix MVC2 <%: %> script block in jQuery script. It takes the user entry, changes the form action attribute with the Url.RouteUrl(), and post the form when the text box loses focus. Here is a section of a appScript.js file
$("input#txtSSN").blur(function () {
if ($(this).val() != undefined && jQuery.trim($(this).val()).length != 0) {
alert('txtSSN.blur() = ' + $(this).val());
var formAction = '<%:Url.RouteUrl(new { controller = "controller1", action = "SSN", ID = escape(jQuery.trim($(this).val())) }) %&开发者_开发问答gt;';
$(this).parents('form:first').form.attr('action', formAction);
$(this).parents('form:first').submit();
} //if
}); //blur
This .js is referenced the Site.master "script src=" block. Everything works except it doesn't post the form with the updated href. Thanks for your help.
You can use the server code blocks only in the aspx files, not in external .js files
精彩评论