In my controller, I have a JsonResult action that returns a list of House objects. My goal is to retrieve this data onclick using ajax and display the JSON data within my view. While I can see the proper response and JSON result in Firebug, I'm not sure how to display it in my view.
function FetchData(id) {
$.ajax({
url: ('/Home/FetchData'),
type: 'POST',
contentType: 'application/json',
data: JSON.stringify({ id: id }),
success: function (result) {
// attempted parsing but didn't work
// result = jQuery.parseJSON(result);
// alert(result.Title);
},
error: function () { alert("error"); }
});
}
public JsonResult FetchData()
{
...
var temp = getMyData...
return Json(temp, JsonRequestBehavior.AllowGet);
}
// View page
<div id="showContent">
// JSON data should appear here
</div>
In Firebug's JSON tab, when success:function(result) is empty, the following data is displayed:
Id 149
PropertyType "Apartment"
StreetNumber "202B"
CityName "Sidney"
Title "My test data"