I'm using Kendo MVC. The data is appearing as the JSON that returned from the controller instead of a formatted KendoGrid. Even when I remove the contents of the entire CSHTML file, it still shows the JSON to the user. The JSON looks to be correctly formatted. What could cause that?
2 Answers, 1 is accepted
0
Ivan Danchev
Telerik team
answered on 05 Jul 2023, 08:35 AM
Hello Rick,
Could you post the declaration of the Grid and the action that returns the data?
Regards,
Ivan Danchev
Progress Telerik
As of R2 2023, the default icon type will be SVG instead of Font. See this blogpost for more information.
public ActionResult getMNotes([Kendo.Mvc.UI.DataSourceRequest] Kendo.Mvc.UI.DataSourceRequest request, string m_key) { if (!string.IsNullOrEmpty(m_key)) { var token = ((ClaimsIdentity)User.Identity).FindFirst("token"); var client_key = ((ClaimsIdentity)User.Identity).FindFirst("client_key");
// The cshtml shows the Delete and Edit button only when the user is an admin var role = ((ClaimsIdentity)User.Identity).FindFirst(ClaimTypes.Role).Value.ToString(); ViewData["role"] = role; mLookUpHTTP http = new mLookUpHTTP();
System.Web.Script.Serialization.JavaScriptSerializer r = new System.Web.Script.Serialization.JavaScriptSerializer(); var jsonObj = r.Deserialize<dynamic[]>(http.getMNotes(token.Value, client_key.Value, m_key)).ToList().ToDataSourceResult(request); return Json(jsonObj, JsonRequestBehavior.AllowGet); } return Json(new { Status = "Error", Message = "No M Passed" }, JsonRequestBehavior.AllowGet); }
Even when I reduce the entire cshtml page to this, it still shows JSON:
I've attached a sample project, in which the Grid is bound to data returned by the getMNotes action. Note that I've commented the conditional logic:
if (!string.IsNullOrEmpty(m_key))
and the missing dependencies and I am returning a sample collection of MModel. I am not sure how m_key is sent to the action. Most likely this is done through the Grid's dataSource Data function. Nevertheless, regardless of returning:
return Json(new { Status = "Error", Message = "No M Passed" }, JsonRequestBehavior.AllowGet);
in both cases I don't get JSON to appear on the page. In both cases the Grid is rendered and the difference is: in the first case the Grid displays the data, in the second case the Grid is displayed empty, since the response contains the error status.
Could you please modify the sample project accordingly so that it demonstrates the issue and attach it back for further review?