question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Returning Json Data from Asp.Net MVC

See original GitHub issue

Hi,

I am facing issue loading data to the grid.Below is my code snippet -

---------------Controller------------------- public class EmailTypeCodeController : BaseController {

public ActionResult Get() {

       EModel vm = new EModel();

        vm.EventCommand = "List";

        vm.HandleRequest();


        return View("Index", Newtonsoft.Json.JsonConvert.SerializeObject(vm));

    }

}

---------------View (CSTML)-------------------- $(function() {

    $("#jsGrid").jsGrid({
        height: "70%",
        width: "100%",
        filtering: true,
        editing: true,
        inserting: true,
        sorting: true,
        paging: true,
        autoload: true,
        pageSize: 15,
        pageButtonCount: 5,
        deleteConfirm: "Do you really want to delete the client?",
        controller: {
            loadData: function (filter) {
                return $.ajax({
                    type: "GET",
                    url: "/EmailTypeCode/Get",
                    data: filter,
                    dataType: "json"
                });
            }
        },
            fields: [
                { name: "CodeID", type: "text", width: 50 },
                { name: "CodeDescription", type: "text", width: 150 },
                { name: "CodeStatus", type: "text", width: 50 },
                { name: "PostingId", type: "text", width: 50 },
                 { name: "RecordCreateDate", type: "text", width: 50 },
                { type: "control" }
            ]
        });
});

Not sure whats the issue.Emodel is collection of objects which is serializing to JSon.Please suggest

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Adondrielcommented, Jul 15, 2016

Also, if you are using ASP with MVC, you can litterally just return an object and it will automatically turn it into JSON for you. one of my controllers for example:

        [HttpGet]
        [ActionName("getAllGAM")]
        public IList<GridAccountMonth> getAllGAM()
        {
            var allPAM = ProjectAccountingMonthService.GetMonthHour();
            IList<GridAccountMonth> allGAM = new List<GridAccountMonth>();
            foreach (ProjectAccountingMonth PAM in allPAM)
            {
                GridAccountMonth GAM = new GridAccountMonth();
                string strDate = PAM.ProjectMonth + "/01/" + PAM.ProjectYear;
                DateTime actualDate = DateTime.Parse(strDate);
                GAM.AccountingMonthID = PAM.AccountingMonthID;
                GAM.MonthHour = PAM.MonthHour;
                GAM.Date = actualDate;
                allGAM.Add(GAM);
            }
            return allGAM.OrderBy(x => x.Date).ToList();
        }
0reactions
tabalinascommented, Jul 27, 2016

Close due to inactivity.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET MVC controller actions that return JSON or partial html
In your action method, return Json(object) to return JSON to your page. public ActionResult SomeActionMethod() { return Json(new {foo="bar", ...
Read more >
Return JSON data from Controller to View in ASP.Net MVC
In this article I will explain with an example, how to use the JsonResult class object for returning JSON data from Controller to...
Read more >
JsonResult In ASP.NET MVC - C# Corner
What is JsonResult ? JsonResult is one of the type of MVC action result type which returns the data back to the view...
Read more >
Format response data in ASP.NET Core Web API
ASP.NET Core MVC supports formatting response data, using specified formats or in response to a client's request.
Read more >
How to return json data from ASP.NET MVC controller?
try this. C#. public JsonResult jsonClassList() { var classes = db.Cls.ToList(); var obj = new { Classes = classes }; return Json(obj, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found