i have a controller action method as below
public JsonResult WidgetDisplay()
List<Users> ul = new List<Users>();
using (var x = new AlfaTestEntities())
var result = from p in x.tblUsers
Users l = null;
foreach (var c in result.ToList())
l = new Users();
l.UserId = c.UserId;
l.WidgetA = (bool)c.WidgetA;
l.WidgetB = (bool)c.WidgetB;
l.WidgetC = (bool)c.WidgetC;
catch (Exception ex)
return Json(ul, JsonRequestBehavior.AllowGet);
where i’m returning a json result to the view , can some one post the code on how to display the json data on the view.
I believe, when you return the JsonResult, you are not using the View in fact – so you may see a browser dialogue box or so to download the json data.
Typical example of the correct usage of it, is – to call this action method from some other view – with xmlHttpRequests or by using jQuery ($.getJson or $.ajax etc). These helper methods can handle the success event by passing the result object (which was
sent from action method) as a parameter for the success events.
Following article helps to demonstrate this:
http://chsakell.com/2013/06/08/retrieve-json-data-from-mvc-controllers-in-asp-net-mvc/ Another discussion which has example: