jQWidgets Forums

jQuery UI Widgets Forums Grid How to retrieve json data from asp.net controller to a view with jqgrid

This topic contains 3 replies, has 2 voices, and was last updated by  thommy 11 years, 8 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author

  • thommy
    Member

    I have a project in ASP.NET MVC 3, and I want to be able to display the records retrieved from a database from a controller to a view. My view implements a jqGrid control. The records will be serialized into JSON and deserialized in the view. The question is how do I retrieve the returned JSON data using javascript to display the data in the Grid?

    Thanks Team.


    Peter Stoev
    Keymaster

    Hi thommy,

    Binding to JSON using ASP .NET MVC3 is described in this help topic: asp.net-bind-jquery-grid-to-sql-database.htm.

    Best Regards,
    Peter Stoev

    jQWidgets Team
    http://www.jqwidgets.com


    thommy
    Member

    Thanks Peter,

    I will look into it.


    thommy
    Member

    mates,

    I am still failing to retrive any data from my controllers. All I am getting is [object],[object],[object],[object] as results. My code is as below:
    ———————————————————————————————————–
    the code part that sends the request to the controller on the server from the view
    ————————————————————————————————————
    @model IEnumerable

    @{
    ViewBag.Title = “Index”;
    }

    $(document).ready(function(){
    var theme = getDemoTheme();
    var title =’Department Details’;
    var url = ‘/Department/GetDepartments’;

    var rowdata =[];

    $.ajax({
    type: ‘POST’,
    url: url,
    datatype: ‘json’,
    success: function(data){
    //rowdata = data;
    alert(data); //here I am alerting just to see the results
    }
    });

    —————————————————————————————–
    the controller code
    —————————————————————————————–

    [HttpPost]
    public JsonResult GetDepartments()
    {
    var result = db.Departments.ToList();
    var departments = from d in result
    select new {d.DeptID,d.DeptName};
    return Json(departments);
    }

    Where Am I going wrong?

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.