Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
132
rated 0 times [  137] [ 5]  / answers: 1 / hits: 8200  / 9 Years ago, wed, march 4, 2015, 12:00:00

I am using action link in my application.



I am having some requirement to call javascript on it's click event.



I know that I can do that using following code.



@Html.ActionLink(Home,Index,Main,new{@onclick=OnIndexCall});


Now on the click event of action link I am computing two values in function and i also need to pass that values to the page in which I am redirecting.



I don't know how can I do that.



Please is there any way to pass the calculated value in from javascript function to redirection page?



EDIT :-



function OnIndexCall(){
var a=10;
var b=a+20;
}


Now i need to pass these a and b values to the redirection page.


More From » asp.net-mvc

 Answers
9

You can pass data through QueryString as shown :-



@Html.ActionLink(Home,Index,Main,new{ @onclick=OnIndexCall(this) });

function OnIndexCall(elem){
var a=10;
var b=a+20;
$(elem).attr('href', $(elem).attr('href') + '?a=' + a + '&b=' + b);
}


Fiddle


[#38838] Tuesday, March 3, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaquelineh

Total Points: 360
Total Questions: 105
Total Answers: 114

Location: Saint Pierre and Miquelon
Member since Fri, Jan 28, 2022
2 Years ago
;