views:

30

answers:

2

I want to call a method in C# from a client side AJAX/JQuery message. The client code is:

        function TestClickFunc(userId) {

            $.ajax({
                url: "/Users/UpdateEmailDistributionListFlag",
                type: "POST",
                data: { "userId" :  userId },
                success: function (data) { alert(data); }
            });

        }

This method gets called with the correct parameter. However in my UsersController, this method does not get called;

   [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult UpdateEmailDistributionListFlag(int userId)
    {
        // db update
        return View();
    }

Can you see why?

A: 

Check if you have a route with parameter userId. In the default route the parameter's name is id, not userId so your method will not be found.

Branislav Abadjimarinov
`type: "POST",`
SLaks
I think my real problem is that I am calling JQuery within a Javascript function, and $ is not being recognised.
arame3333
You can test this by replacing $ with jQuery like:jQuery.ajax({...
Branislav Abadjimarinov
A: 

What I found was that the CDN was not working;

I can't see the spelling mistake, but it worked when I used my local script!

arame3333