将JavaScript传递给@ Html.Actionlink

时间:2014-03-25 10:08:09

标签: javascript asp.net-mvc

我想将JavaScript值传递到@Html.ActionLink("Sửa", "EditShopping","Home",{Id=}),其中Id是从JavaScript传递的

详细的代码如下(dataTable plugin jQuery):

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

2 个答案:

答案 0 :(得分:1)

尝试这样:

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

答案 1 :(得分:0)

传递给@Html.ActionLink的参数最终将由MVC添加到查询字符串参数中。

您可以使用原始网址添加查询字符串值,如下所示

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