2013-05-20 10 views
3

我想用在ASP.NET MVC动作链接JQuery的变量/值,所以我需要在下面的代码行使用$("#JobGR :radio:checked").val()ASP.NET MVC动作链接内使用jQuery变量

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

我在$上收到错误,请帮我解决这个问题。

回答

1

你不能在Action中使用动态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>