在jQuery中嵌入MVC脚本块 [英] embed MVC script block in jQuery

查看:107
本文介绍了在jQuery中嵌入MVC脚本块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在jQuery脚本中混合使用MVC2<%:%>脚本块.它需要用户输入,使用Url.RouteUrl()更改表单操作属性,并在文本框失去焦点时发布表单.这是appScript.js文件的一部分

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())) }) %>';
        $(this).parents('form:first').form.attr('action', formAction);
        $(this).parents('form:first').submit();
    } //if
}); //blur

此.js被引用为Site.master"script src ="块.一切正常,除了不发布具有更新的href的表单.感谢您的帮助.

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.

推荐答案

您只能在aspx文件中使用服务器代码块,而不能在外部.js文件中使用

You can use the server code blocks only in the aspx files, not in external .js files

这篇关于在jQuery中嵌入MVC脚本块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆