jquery - 在 ASP.NET MVC Action 链接中使用 JQuery 变量

标签 jquery asp.net-mvc

我想在 ASP.NET MVC Action 链接中使用 JQuery 变量/值,因此我需要在下面使用 $("#JobGR :radio:checked").val()代码行:

     @Html.ActionLink("Insert", "InsertPersonJob","Reg" , new {JobNo=$("#JobGR :radio:checked").val(), PersonID=User.Identity.Name },null)

我在 $ 上收到错误,请帮助我如何解决此问题。

最佳答案

您不能在 ActionLink 中使用动态 javascript,因为 ActionLink 生成是在渲染 html 操作中。

但是你可以使用占位符之类的东西:

<a href="#" data-url="@Html.ActionLink("Insert", "InsertPersonJob","Reg" , new { JobNo="{replaceMe}", PersonID=User.Identity.Name },null)" class="replacedLink">Link</a>

<script>

$("a.replacedLink").click(function(){
   window.location = $(this).attr("data-url").replace("{replaceMe}", $("#JobGR :radio:checked").val());
});

</script>

关于jquery - 在 ASP.NET MVC Action 链接中使用 JQuery 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16646076/

相关文章:

c# - WebRequests 很慢(需要 4 秒)我如何加快它们的速度?

javascript - MVC - PartialView 在 View 中找不到事件

jQuery 与 Scriptaculous 冲突

jQuery animate() 没有为左属性设置动画

javascript - 按另一个数组对对象数组进行排序

asp.net-mvc - 如何将蒙版放入文本框中?

jQuery 下载列表中的所有文件

javascript - jquery 加载窗口未执行

javascript - 类似于 ASP.NET MVC 中的 SO 的投票系统

c# - 刷新 Json 局部 View