I am trying to pass some text from a textbox to a controller to get JSON results like so
function invokeAction() {
var searchText = $("#SearchTextBox").val();
// Invoke MVC controller action
$.getJSON("/Home/Results/" + searchText, bindResults);
}
If I put an alert here I can see that searchText definately has a value, but when I put a break point on this controller action:
public ActionResult Results(string search)
{
var r = from t in db.Restaurants
where SqlMethods.Like(t.Name, "%" + search + "%") || SqlMethods.Like(t.Postcode, search + "%") || SqlMethods.Like(t.CuisineType.Type, search + "%")
orderby t.Name ascending
orderby t.Rating descending
orderby t.NumOfViews
descending
select t;
return Json(r.ToList());
}
The string passed in is null, yet when I check the http context in the debugger my searchtext is a part of the url.
As this is null the query returns no results.
Am I missing something here?