Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: jQuery
Hi,
I am working on MVC application.I have a method in controller as below:
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:
function Navigate(action) {
    
    $.ajax({ url: customerIdURL, data: { viewAction: "action"} });
} 
But the problem is that viewAction is always null..Please help me out.
Posted 29-Jun-12 3:25am
Edited 29-Jun-12 5:04am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here is an article that will help you pass parameters:
 
Invoke Server Methods From Client Side Using jQuery AJAX in ASP.NET[^]
  Permalink  
Comments
Sandeep Mewara at 29-Jun-12 11:09am
   
Good reference for jQuery Ajax, but it misses the MVC flavor in it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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)[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

use this
function Navigate(action) {
 
    $.ajax({ url: customerIdURL, data: "{ viewAction: "+ action+"}",
type="post" });
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

function Navigate(action) {
 
    $.ajax({ url: customerIdURL, data: { viewAction: action} });
}
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 9 Jul 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100