c# - 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 错误返回。
我已经在没有路由的新控制器中尝试了最基本的调用,并且按照一个普通的示例,但是我得到了相同的结果。
解决方案
我找到了我的答案,尽管在黑暗中经历了很多坎坷,而且 Telerik 自己没有做出任何有用或有价值的回应。
.Read(r => r.Action("RefreshRecommendationGridData", "ReportLookup").Data("sendAntiForgery"))
然后在javascript中
function sendAntiForgery() {
return { "__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val() }
}
推荐阅读
- javascript - 更改音频/源标签下载名称
- docker - 来自 Jenkins 在 MacOS 上的“Docker:找不到命令”
- amazon-web-services - AWS Cognito - resendConfirmationCode '用户已经确认。
- c++ - 使用 OpenMP 获得完整、未损坏的输出需要什么?
- c++ - C++ - 打印素数直到 N
- sql - SQL Server 列除以具有空值的列
- salesforce - 将 Zendesk 票发送给 salesforce
- java - 重新生成jHipster实体时如何防止自定义存储库方法被删除
- python - 获取 MongoDB 自动生成的 UUID 并将其插入当前记录
- angular - 我们可以覆盖 Angular 应用程序中 SimpleChanges 的值吗?