Controller getting NULL value?

Posted by RSolberg on Stack Overflow See other posts from Stack Overflow or by RSolberg
Published on 2010-05-25T22:49:15Z Indexed on 2010/05/25 22:51 UTC
Read the original article Hit count: 348

Filed under:
|
|
|

I'm trying to make a call to a controller via jQuery $.post, but the parameter for my controller method keeps getting a NULL value despite it appearing to be setup similar to other controller methods.

CONTROLLER

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult SearchWeatherLocations(string searchFor)
{
    //Do Some Magic
}

GLOBAL.ASAX

routes.MapRoute("SearchWeatherLocations", "Home/SearchWeatherLocations/{searchFor}",
new
{
    controller = "Home",
    action = "SearchWeatherLocations"
});

jQuery Call From View

<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        GetWeatherLocations("seat");
    });
    function GetWeatherLocations(sSearchFor) {
        var divToBeWorkedOn = '#locations';
        var webMethod = '<%= Url.Action("SearchWeatherLocations", "Home") %>/';
        var url = webMethod + sSearchFor;
        $.post(url, function (data) {
            $('#locations').children().remove();
            for (var count in data) {
                $('#locations').append("<li>" + data[count].LocationName + "&nbsp;(" + data[count].LocationCode + ")</li>");
            }
        });
    }
</script>

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET