Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a local variable called mode in JQuery function. Based on the radiobutton selection, this variable value is set in JQuery function.

Now i want to access this value in COntroller? How can we do this.

$(':radio').click(function() { var mode = this.value; });

Now How can I access this mode variable in my controller method.

[HttpPost] public ViewResult ExportToExcel(string mode) { }

Appreciate your responses.

Thanks

share|improve this question
add comment

4 Answers

You should perform either synchronous request (form submit with mode variable set) or AJAX POST request, depends on your application design

share|improve this answer
add comment

Have you thought about creating a hidden field on the page and then updating its value from jQuery? You can then just read in this value as an additional POST field when the page is submitted to the server.

share|improve this answer
add comment

because mode is declared inside the anonymous function, it cannot be access outside of it. you can create a callback that uses the mode variable, or make it more global so you can access it outside the function.

share|improve this answer
add comment

You can do something like (or any other ajax method you want to call there); $.post('yourController/ExportToExcel/'+mode,.../the rest of the params/);

in your anonymous function to make it like;

$(':radio').click(function() { var mode = this.value; $.post('yourController/ExportToExcel/'+mode,.../the rest of the params/); });

share|improve this answer
 
I tried $.post('Home/ExportToExcel', {"mode": mode }); Still the value of mode in controller is null. –  Rita Feb 5 '10 at 19:08
 
Did you try my given url format with your controller function: [HttpPost] public ViewResult ExportToExcel(string mode) {} ? that way, you will have the value of mode in 'mode' parameter –  Naveed Feb 7 '10 at 6:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.