MVC2 Json request not actually hitting the controller

Posted by SlackerCoder on Stack Overflow See other posts from Stack Overflow or by SlackerCoder
Published on 2010-04-30T17:57:17Z Indexed on 2010/04/30 18:37 UTC
Read the original article Hit count: 226

Filed under:
|

I have a JSON request, but it seems that it is not hitting the controller. Here's the jQuery code:

$("#ddlAdminLogsSelectLog").change(function() {
        globalLogSelection = $("#ddlAdminLogsSelectLog").val();

        alert(globalLogSelection);

        $.getJSON("/Administrative/AdminLogsChangeLogSelection", { NewSelection: globalLogSelection }, function(data) {
            if (data.Message == "Success") {
                globalCurrentPage = 1;

            } else if (data.Message == "Error") {
                //Do Something
            }
        });
    });

The alert is there to show me if it actually fired the change event, which it does.

Heres the method in the controller:

public ActionResult AdminLogsChangeLogSelection(String NewSelection)
    {
        String sMessage = String.Empty;
        StringBuilder sbDataReturn = new StringBuilder();

        try
        {
            if (NewSelection.Equals("Application Log"))
            {
                int i = 0;
            }
            else if (NewSelection.Equals("Email Log"))
            {
                int l = 0;
            }
        }
        catch (Exception e)
        {
            //Do Something
            sMessage = "Error";
        }

        return Json(new { Message = sMessage, DataReturn = sbDataReturn.ToString() }, JsonRequestBehavior.AllowGet);
    }

I have a bunch of Json requests in my application, and it seems to only happen in this area. This is a separate area (I have 6 "areas" in the app, 5 of which work fine with JSON requests). This controller is named "AdministrativeController", if that matters.

Does anything jump out anyone as being incorrect or why the request would not pass to the server side?

© Stack Overflow or respective owner

Related posts about asp.net-mvc-2

Related posts about JSON