I am working with MVC3. I have a javascript function which makes an ajax call to mvc3 controller action. When i send null in the data, it calls the controller action. but when I try to send location in data it gives javascript error i.e. ‘this is not defined’.
function getPictureContent(location)
{
var pictures = getLocationPictures(location);
var content = "<div id=markerpictures></div>";
return content;
}
function getLocationPictures(location) {
var pics;
$.ajax({
type : "POST",
url : "/Home/GetLocationPictures",
data : {'location' : location},
contentType : "application/json; charset=utf-8",
dataType : 'json',
async : false,
success : function (data) {
pics = data;
}
});
return pics;
}
Here is the controller action:
public JsonResult GetLocationPictures(string location)
{
List<string> pictures = new List<string>();
return Json(pictures);
}
Try this.. Location should be string.Be sure that will string.