简体   繁体   中英

Pass JavaScript to @Html.Actionlink

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=})';
  }
}

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>';
  }
}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM