How can i pass the json output from controller action to its view ? As I tried to send before, My code is :
public ActionResult Index()
{
Guid Id = new Guid("66083eec-7965-4f3b-adcf-218febbbceb3");
List<TasksToOfficer> officersTasks = tasks_to_officer_management.GetTasksToOfficers(Id);
return Json(officersTasks)
}
it is asking for JsonRequestBehavior.AllowJson
like parameter. I know it is new in asp.net mvc 2 but as redirect to view there is nothis happens but asking for download the json output file. I want to work with returned data in my jQuery .But something going wrong there. and if I removed the parameter then it is showing error :
This request has been blocked because sensitive information could be disclosed to third party web sites when this is used in a GET request. To allow GET requests, set JsonRequestBehavior to AllowGet.
How to avoid this and get json data at view ?
1 Answer 1
Here is an example of what you are trying to do. First in your view you call $.getJSON to grab the JSON data from the action:
$.getJSON('/Data/StockQuote', function(data) {
if (data.success) {
ShowStockQuote(data);
}
});
Then your action will look like this:
public JsonResult GetStockQuote()
{
JsonResult result = new JsonResult()
{
Data = new {
lastTradePrice = 50,
lastUpdated = "10/1/2010",
expirationDate = "10/2/2010",
success = true
},
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
return result;
}
Once the JSON data is returned from your action to the $.getJSON you can use data to access all the values off of the JSON object. So data.success will give you the success and so forth.