Tried reading other similar questions but can't quite detect what's wrong with mine. I'm attempting to build an ajax call as follows:
$.ajax({
type: "POST",
url: '@Url.Action("Search", "Map")', // Map Controller, Search Action
data: JSON.stringify({ "Location": x }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var table = "<table class='table'>";
$.each(data, function (index, value) { // For each element in data:
table += "<tr><td>" + value.title + "</td></tr>"; // add it to the table list
var latlng = new google.maps.LatLng(value.latitude, value.longitude);
var marker = new google.maps.Marker({
position: latlng,
map: map
});
gmarkers.push(marker);
});
table += "</table>";
$("#myData").html(table);
}
});
It's supposed to send the text acquired from:
$("#txtSearch").keyup(function () {
var x = $("#txtSearch").val();
Now the text is acquired correctly, therefore 'x' does have a value when it's submitted. But once the ajax request above is processed the method being called which is the Search Action under the MapController is called with a null parameter:
[HttpPost]
public ActionResult Search (string title)
{
Entities mapEntity = new Entities();
string userId = User.Identity.GetUserId();
var result = mapEntity.Markers.Where(x => x.title.StartsWith(title) && x.UserId == userId).ToList();
return Json(result, JsonRequestBehavior.AllowGet);
}
As long as the title remains null I can't really do anything with it... Appreciate any help on resolving this issue.