我使用bootstrap数据表来创建一个显示链接按钮以重定向到另一个视图的列,问题是我从jquery获取语法错误而且我没有成功修复它
以下是我收到语法错误的相关部分:
return '<button type="button"class="btn btn-default" onclick="location.href='@Url.Action("IncidentesDetalle", "ServiciosController", new { Id = "1" })'"><i class="fa fa-eye"></i></button>'
任何帮助将不胜感激。
答案 0 :(得分:0)
试试这个,它会起作用:
string path = "'@Url.Action('IncidentesDetalle', 'ServiciosController', new { Id = '1' })'";
return "<button type='button' class='btn btn-default' onclick='location.href="+path+"'><i class='fa fa-eye'></i></button>";
答案 1 :(得分:0)
我猜您应该将字符串更改为:
return '<button type="button" class="btn btn-default" onclick="location.href=\'@Url.Action("IncidentesDetalle", "ServiciosController", new { Id = "1" })\'"><i class="fa fa-eye"></i></button>'
因为在您的原始代码中,单引号仅在href=
之后关闭并再次在><i
之前打开。因此像@Url....
这样的返回字符串的一部分变成了无效代码。因此错误。