我想在 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/