0

I want to pass JavaScript value into @Html.ActionLink("Sửa", "EditShopping","Home",{Id=}) where Id is passed from JavaScript

Pieces of detail code as below(dataTable plugin jQuery):

{
  "bSearchable": false,
  "bSortable": false,
  "mData": 0,
  "mRender": function (data, type, full) {
      return '@Html.ActionLink("Sửa", "EditShopping", "Home", new {Id=})';
  }
}

2 Answers 2

1

try like this:

var YourId='1';
var url = '@Url.Action("EditShopping", "Home")';

url = url + "?Id="+ YourId;

{
  "bSearchable": false,
  "bSortable": false,
  "mData": 0,
  "mRender": function (data, type, full) {
      return '<a href="'+url+'">Link</a>';
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks you, Ehsan Sajjad.
you are welcome @vduman, mark it answer if it worked for you, and you can vote up as well, if you want..:)
0

The parameters passed to @Html.ActionLink will be finally added to the query string parameter by MVC.

You can add the query string value with the original url like below

"mRender": function (data, type, full) 
{
  return '@Html.ActionLink("Sửa", "EditShopping", "Home")'+'?Id='+YourJSVariable;
}

2 Comments

@vmduan, Why it wont work? For your code the url should be /EditShopping/Sửa?Id=2. Please make sure the url is perfect
Thanks Murali Murugesan, but it show 'Sửa?id=2' with 'Sửa' is link map with <a href="/Home/EditShopping" value="Sửa"/>

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.