2 Answers, 1 is accepted
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:
<p>xxxxx</p>
@(Html.Kendo().Grid<patha.pathb.Models.MModel>()
.Name("xxx")
);
Rick,
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(jsonObj, JsonRequestBehavior.AllowGet);
or:
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?

Hi Ivan. Thanks for looking into this! This is working now. I believe that the source of the problem was this line of JavaScript in my cshtml:
var url = '@Url.Action("addMeterNote", "Default")
which should have been:
var url = '@Url.Action("addMeterNote", "Default")';
Apparently it was adding some of the subsequent lines of code to the url variable instead of using treating them as code.
Thanks again! - Rick
Rick,
Thank you for the follow up. I am glad you've identified what was causing the issue and it is now fixed.
Regards,
Ivan Danchev
Progress Telerik