开发者

embed MVC script block in jQuery

开发者 https://www.devze.com 2023-03-14 18:22 出处:网络
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

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号