Click here to Skip to main content
12,697,783 members (26,210 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: jQuery MVC4
Javascript code
<script type="text/javascript" lang="Javascript">
function ChkBx(Id) {
        var url = '/Grid/Edit/' 
        $.ajax({
            url: url,
            data: {id = Id},     
            type: 'GET',
            datatype: 'html',
            success: function(data) { alert('Success'); },
            error: function() { alert('Failure'); }
        });      
    }
</script>


Controller Grid and Edit action
 [HttpGet]
        public ActionResult Edit(int Id)
        {
            return View();
        }


Problem: javascript is not firing the event Edit action.

Is anything missing in my code?

Thank you
Posted 20-Nov-12 21:09pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You can try this. You have to send Data in this format.

$.ajax({ 
     url: url,
     data: "{ 'id' :'" + Id + "'}",     
     type: 'GET',
     datatype: 'html',
     success: function(data) { alert('Success'); },
     error: function() { alert('Failure'); }      
});      


also please check your url :)

For more information check Here[^]
  Permalink  
Comments
Swathi Nagaraj 21-Nov-12 4:17am
   
var url = '/Grid/Edit/'
GridController is my controller and Edit is action.

The syntax of setting Url is /Controller/action.
what else I have to check?
Thank you Tajbir
Sk. Tajbir 21-Nov-12 4:28am
   
Did you check the data ? also please give same name to Edit function's parameter name and data parameter in ajax call. Let me know.
Swathi Nagaraj 21-Nov-12 4:49am
   
I have changed to
data: {Id = Id},
instead of
data: {id = Id},

But still not firing
Swathi Nagaraj 21-Nov-12 4:51am
   
Can you please tell me how this ajax url will work.
Sk. Tajbir 21-Nov-12 4:55am
   
please use: data: "{ 'Id' : '" + Id + "'}", (direct use this line)
Swathi Nagaraj 21-Nov-12 5:09am
   
Sorry I may troubling you a lot.
I tried with the above code but still Its not firing.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2017
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