简体   繁体   English

将JavaScript传递给@ Html.Actionlink

[英]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 我想将JavaScript值传递到@Html.ActionLink("Sửa", "EditShopping","Home",{Id=}) ,其中从JavaScript传递ID

Pieces of detail code as below(dataTable plugin jQuery): 详细代码如下(dataTable插件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. 传递给@ Html.ActionLink的参数最终将由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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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