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.
My jquery function:
$('#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.
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:
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);
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.