Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

1 solution

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[^]
 
Share this answer
 
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)

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