Returning Json Data from Asp.Net MVC
See original GitHub issueHi,
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:
- Created 7 years ago
- Comments:10 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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:
Close due to inactivity.