Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am working on MVC application.I have a method in controller as below:
C#
public ActionResult LogOn(string viewAction)
        {
            if (string.IsNullOrEmpty(viewAction))
                return View();
            else
                return null;
        }


Based on the viewAction i want to perform some action but this viewAction never gets initialised.I am using jquery ajax to pass parameters as below:
JavaScript
function Navigate(action) {
    
    $.ajax({ url: customerIdURL, data: { viewAction: "action"} });
} 

But the problem is that viewAction is always null..Please help me out.
Posted
Updated 29-Jun-12 5:04am
v2

Here is an article that will help you pass parameters:

Invoke Server Methods From Client Side Using jQuery AJAX in ASP.NET[^]
 
Share this answer
 
Comments
Sandeep Mewara 29-Jun-12 11:09am    
Good reference for jQuery Ajax, but it misses the MVC flavor in it.
I doubt if the above article covers jQuery Ajax parameters to MVC controller, have a look at this one: Refreshing content of the table using AJAX in ASP.NET MVC (jQuery DataTables and ASP.NET MVC integration - Part III)[^]
 
Share this answer
 
use this
PHP
function Navigate(action) {

    $.ajax({ url: customerIdURL, data: "{ viewAction: "+ action+"}",
type="post" });
}
 
Share this answer
 
PHP
function Navigate(action) {

    $.ajax({ url: customerIdURL, data: { viewAction: action} });
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900