Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在ASP.NET MVC操作链接中使用JQuery变量_Jquery_Asp.net Mvc - Fatal编程技术网

在ASP.NET MVC操作链接中使用JQuery变量

在ASP.NET MVC操作链接中使用JQuery变量,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我想在ASP.NET MVC操作链接中使用JQuery变量/值,因此我需要在下面的代码行中使用$(“#JobGR:radio:checked”).val(): @Html.ActionLink("Insert", "InsertPersonJob","Reg" , new {JobNo=$("#JobGR :radio:checked").val(), PersonID=User.Identity.Name },null) 我在$上收到一个错误,请帮助我如何解决此问题。问题是Acti

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

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

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

问题是ActionLink是在服务器端生成的。JQuery只存在于客户端。 没有简单的方法可以做到这一点。您必须在客户端构建此链接才能使其正常工作

关于此问题,有一些主题如下:


以上每一种方法对这个问题都采取了不同的方法

您不能在ActionLink中使用动态javascript,因为ActionLink的生成是在render html action中进行的

但您可以使用类似占位符的内容:

<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>

$(“a.replacedLink”)。单击(函数(){
window.location=$(this.attr(“数据url”).replace(“{replaceMe}”,$(“#JobGR:radio:checked”).val());
});