Controller getting NULL value?
- by RSolberg
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 + " (" + data[count].LocationCode + ")</li>");
}
});
}
</script>