首页 > 解决方案 > Kendo MVC Core - 网格 - 无法使用路由获取数据 - 400 错误请求

问题描述

我刚刚签了一份新合同,虽然我习惯使用 Kendo,但这是我第一次使用 Kendo Core。

通常我会有我的控制器,我的动作和绑定使用

.DataSource(ds => ds.Read(r => r.Action("RefreshRecommendationGridData", "ReportLookup")))

但是我所在的公司大量使用路由

 [Authorize]
[Route("report-lookups")]
public class ReportLookupController : Controller
{
    [AccessRights("Lists")]
    [HttpPost]
    [Route("report-lesson-recommendations/manage")]
    public async Task<IActionResult> RefreshRecommendationGridData([DataSourceRequest] DataSourceRequest request)
    {
        var result = await _cacheService.SearchForReportLessonRecommendationsAsync(null);
        return Json(result.ToDataSourceResult(request));
    }
}

尝试此操作并查看开发人员工具和网络以及使用时

.DataSource(ds => ds.Read(r => r.Url("manage"))

我收到 400 Bad Reqest 错误。

我想我错过了一些东西,但是我完全不知所措。我怀疑它很简单,但是,我在 Telerik 网站上找不到任何有用的东西。

如果我将其更改为 a[HttpGet]那么这将作为 404 错误返回。

我已经在没有路由的新控制器中尝试了最基本的调用,并且按照一个普通的示例,但是我得到了相同的结果。

标签: c#asp.net-corekendo-uikendo-gridkendo-asp.net-mvc

解决方案


我找到了我的答案,尽管在黑暗中经历了很多坎坷,而且 Telerik 自己没有做出任何有用或有价值的回应。

.Read(r => r.Action("RefreshRecommendationGridData", "ReportLookup").Data("sendAntiForgery"))

然后在javascript中

function sendAntiForgery() {
    return { "__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val() }
}

推荐阅读