i have enabled the Content Security Policy (CSP) in my mvc project i have view where i have mvc grid hierarchy
https://demos.telerik.com/aspnet-mvc/grid/hierarchy exmple i have used
when i add Deferred to the grid the inner grid wont work
i get an error
jquery-3.6.3.min.js:2 Uncaught Error: Syntax error, unrecognized expression: #Grid_#=EmployeeID#
at se.error (jquery-3.6.3.min.js:2:13911)
at se.tokenize (jquery-3.6.3.min.js:2:21922)
at se.select (jquery-3.6.3.min.js:2:22749)
at Function.se (jquery-3.6.3.min.js:2:7196)
at a.find (jquery-migrate.min.js:2:1675)
at E.fn.init.find (jquery-3.6.3.min.js:2:25319)
at E.fn.init (jquery-3.6.3.min.js:2:25808)
at new a.fn.init (jquery-migrate.min.js:2:1276)
at E (jquery-3.6.3.min.js:2:1051)
at HTMLDocument.<anonymous> (Index:505:1618)
code cshtml
@using PM.Common;
@using PM.Common.Helper;
@using PM.PartnerManagement.Models;
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
@(Html.Kendo().Grid<PM.PartnerManagement.Common.Employeeviewmodel>()
.Name("grid")
.Columns(columns =>
{
columns.Bound(e => e.FirstName).Width(130);
columns.Bound(e => e.LastName).Width(130);
columns.Bound(e => e.Country).Width(130);
columns.Bound(e => e.City).Width(110);
columns.Bound(e => e.Title);
})
.Sortable()
.Pageable()
.Scrollable()
.ClientDetailTemplateId("template")
.HtmlAttributes(new { style = "height:600px;" })
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(6)
.Read(read => read.Action("HierarchyBinding_Employees", "Test"))
)
.Events(events => events.DataBound("dataBound")).Deferred()
)
<script id="template" type="text/kendo-tmpl" >
@(Html.Kendo().Grid<PM.PartnerManagement.Common.orderViewmodel>()
.Name("Grid_#=EmployeeID#") // template expression, to be evaluated in the master context
.Columns(columns =>
{
columns.Bound(o => o.OrderID).Width(110);
columns.Bound(o => o.ShipCountry).Width(150);
columns.Bound(o => o.ShipAddress).ClientTemplate("\\#= ShipAddress \\#"); // escaped template expression, to be evaluated in the child/detail context
columns.Bound(o => o.ShipName).Width(300);
})
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Read(read => read.Action("HierarchyBinding_Orders", "Test", new { employeeID = "#=EmployeeID#" }))
)
.Pageable()
.Sortable().Deferred()
.ToClientTemplate()
)
</script>
<script nonce="@PM.Common.Constant.Nonce">
function dataBound() {
this.expandRow(this.tbody.find("tr.k-master-row").first());
}
</script>
<script nonce="@Constant.Nonce">
@Html.Kendo().DeferredScripts(false);
</script>
CS
using PM.Portal.Controllers;
using PM.Portal.Filters;
using System.Web.Mvc;
using PM.Core.Repositories.Interface;
using Kendo.Mvc.UI;
using System.IO;
using Newtonsoft.Json;
using System.Collections.Generic;
using Kendo.Mvc.Extensions;
namespace PM.PartnerManagement.Controllers
{
[Authorize(Order = 1)]
public class TestController : BaseController
{
#region GLOBAL VARIABLES USED IN THIS CONTROLLER
ICommonRepository _repoCommon = new CommonRepository();
IWorkOrderRepository _repoWorkOrder = new WorkOrderRepository();
#endregion
//[WebRoleFilter]
public ActionResult Index()
{
return View();
}
public JsonResult HierarchyBinding_Employees([DataSourceRequest] DataSourceRequest request)
{
string text = System.IO.File.ReadAllText(@"C:\Neeraj Repo\PartnerManagement\Dev\Bill360_Dev\Bill360_New\PM.PartnerManagement\Json\Employee.json");
List<PM.PartnerManagement.Common.Employeeviewmodel> GetEmployees = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PM.PartnerManagement.Common.Employeeviewmodel>>(text);
return Json(GetEmployees.ToDataSourceResult(request),JsonRequestBehavior.AllowGet);
}
public JsonResult HierarchyBinding_Orders(int employeeID, [DataSourceRequest] DataSourceRequest request)
{
string text = System.IO.File.ReadAllText(@"C:\Neeraj Repo\PartnerManagement\Dev\Bill360_Dev\Bill360_New\PM.PartnerManagement\Json\order.json");
List<PM.PartnerManagement.Common.orderViewmodel> Getorders = Newtonsoft.Json.JsonConvert.DeserializeObject<List<PM.PartnerManagement.Common.orderViewmodel>>(text);
return Json(Getorders.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
}
}
}