I have created a view and a controller, the controller I am wanting to return some search results. I am calling the controller using jquery
<input type="text" id="caption" />
<a href="#" id="search">Search</a>
<script>
$("#search").click(function () {
alert('called');
var p = { Data: $('#search').val() };
$.ajax({
url: '/Ingredients/Search',
type: "POST",
data: JSON.stringify(p),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert(data);
},
error: function () {
alert("error");
}
});
});
My controller looks like this
[HttpPost]
public ActionResult Search(string input)
{
var result = _db.Ingredients.Where(i => i.IngredientName == input);
return new JsonResult() {Data = new {name="Hello There"}};
}
My problem is I am not sure how to get the varible from my jquery call into the controller, I have put a breakpoint on the controller and its been hit however the input string is always null.
What have I done wrong?