[英]Using jquery variable in Razor
I have a table in which there are input buttons with attribute data. 我有一个表,其中有带有属性数据的输入按钮。 I want to read the value of this attribute and pass it on to razor's routeurl.
我想读取此属性的值并将其传递给razor的routeurl。
My jquery function: 我的jQuery函数:
$('#table').on("click", "input.myClass", function () {
var abc = $(this).attr('data');
var myroute = @Url.RouteUrl("Routename", abc)-- > It says abc not defined
//use myroute
});
what i have experience you can't use js variable in razor but vica vera is possible. 我有什么经验,你不能在剃须刀中使用js变量,但vica vera是可能的。
so You have to achieve it by doing something like this: 因此,您必须通过执行以下操作来实现它:
var myroute = '@Url.RouteUrl("Routename")';
myroute = myroute +"/"+ abc;
Suppose route rendered by RouteUrlHelper is: 假设由RouteUrlHelper呈现的路由为:
var myroute = '/Home/About';
var abc = 1;
concatenate value with it: 将值与其连接:
myroute = myroute +"/"+ abc;// ---> /Home/About/1
Another method I use is this one: 我使用的另一种方法是:
var myroute = "@Url.RouteUrl("Routename","-abc")";
myroute = myroute.replace("-abc", abc);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.