最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Unable to pass filters for kendo grid along with a parameter in ASP.NET MVC - Stack Overflow

programmeradmin4浏览0评论

I have my controller method as follows

[HttpGet]
public JsonResult GetClientAccount([DataSourceRequest] DataSourceRequest request, string partyId)
{
  try
  {
    using (var client = GetWebClient(WebClientContentType.JSON))
    {
       string clientApiResponse = client.DownloadString(new Uri(_webApiUrl + "/api/Client/GetClientAccountinfo/" + partyId));
       var rawResponse = JsonConvert.DeserializeObject<string>(clientApiResponse);
       ClientAccountJsonViewModel clientInfo = JsonConvert.DeserializeObject<ClientAccountJsonViewModel>(rawResponse);

        if (clientInfo?.Data == null || !clientInfo.Data.Any())
        {
          return Json(new DataSourceResult { Data = new List<ClientAccountInvoice>(), Total = 0 }, JsonRequestBehavior.AllowGet);
        }

        var clientAccs = clientInfo.Data
                    .Select(data => new ClientAccountInvoice
                    {
                        Description = data.InvoiceDescription,
                        InvoiceNumber = data.InvoiceNumber ?? ""
                    })
                    .AsQueryable(); // Convert to IQueryable for server-side operations

        // Apply server-side operations (filtering, sorting, paging)
        var result = clientAccs.ToDataSourceResult(request);

        // The Total is automatically set by ToDataSourceResult based on filtered count
        return Json(result, JsonRequestBehavior.AllowGet);
      }
    }
    catch (Exception ex)
    {
      // Log error
      return Json(new DataSourceResult { Data = new List<ClientAccountInvoice>(), Total = 0 }, JsonRequestBehavior.AllowGet);
    }
}

My .cshtml is as follows:

<div id="grid"></div>

$("#grid").kendoGrid({
        dataSource: {
            transport: {
                read: {
                    url: "/Client/GetClientAccount",
                    type: "GET",
                    dataType: "json",
                    data: function () {
                        return { partyId: $(".clientnumber-text").text().trim() };
                    }
                }
            },
            serverPaging: true,
            serverSorting: true,
            serverFiltering: true,
            columns: [{ field: "InvoiceNumber", title: "Invoice No" }],
            pageSize: 20, // Adjust as needed
            schema: {
                data: "Data",
                total: "Total"
            }
        },
        columns: [
            { field: "Description", filterable: false, title: "Description", width: "200px" },
            {
                field: "InvoiceNumber", title: "InvoiceNumber", width: "120px",
                template: "#if(TransactionType && InvoiceNumber && InvoiceNumber.trim() != '' && InvoiceNumber != '0') {#" +
                    "<a style='cursor: pointer;' " +
                    "id='#=InvoiceNumber#' " +
                    "onclick='downloadDoc(\"#=InvoiceNumber#\", #=getHeaderMenuId()#, \"#=SourceSystem#\")' " +
                    "name='#=InvoiceNumber#'>#=InvoiceNumber#</a>" +
                    "#} else {# #=InvoiceNumber# #} #"
            },
        ],
        pageable: true,
        sortable: true,
        filterable: true
    });

But when I apply filter on InvoiceNumber, I am unable to see that on server side

I tried changing to post method but still the same do can some one let me know where I am doing wrong.

发布评论

评论列表(0)

  1. 暂无评论