I'm using jQuery autocomplete plugin from jQuery website calling the controller url which return json in return. The problem is the parameter sent to the controller is always null.
Here is the in-browser jQuery code for the autocomplete:
$(document).ready(function() {
var url = "/Building/GetMatchedCities";
$("#City").autocomplete(url);
});
and here is the ASPNET MVC controller signature in C#:
public JsonResult GetMatchedCities(string city)
{
..
return this.Json(query, JsonRequestBehavior.AllowGet);
}
Thanks in advance,
Mohammad
I had this same problem. After looking at the URL created by JQuery in Fiddler, I discovered that it looked like this: /MyController/MyMethod?term=x. So I changed my method signature to use the parameter name 'term' instead of 'q' ('q' is shown in the JQuery website autocomplete examples.). This fixed the problem and I was able to still return the JsonResult I needed.
public JsonResult MyMethod(string term)
{
...
return Json(query, JsonRequstBehavior.AllowGet);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With