3

I want to use the JQuery variable/value in the ASP.NET MVC Action link, So I need to use $("#JobGR :radio:checked").val() in below line of code :

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

I receive an error on $ , Please help me how I can solve this issue.

2 Answers 2

1

You can't use dynamic javascript inside ActionLink, because ActionLink generation is in render html action.

But you can use something like placeholder:

<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>
Sign up to request clarification or add additional context in comments.

Comments

1

The problem is that ActionLink is generated on server side. JQuery exist only on client side. There is no simple way to do this. You have to build this link on client side to make it working.

There are some topics about this problem like:

Every above takes different approach on this problem

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.