This is a migrated thread and some comments may be shown as answers.

400 Bad Request - Grid AutoBind, read and refresh

2 Answers 690 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 16 Apr 2019, 07:40 AM

I have just started a new contract and althought I am used to using Kendo, this is my first experience using Kendo Core.
Typically I would have my controller, and my action and bind on this using   

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

However the firm that I am at heavily uses routing

[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));
        }
    }

When attempting this and looking through developer tools and the network and when using

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

I get a 400 Bad Reqest error.

I guess I am missing something, however what that is I am at a complete loss. I suspect its something quite simple, however, I cannot find anything on Telerik site that will help.

When inspecting the headers in Fiddler, I cant see anything wrong. 


2 Answers, 1 is accepted

Sort by
0
Simon
Top achievements
Rank 1
answered on 16 Apr 2019, 02:59 PM

found the issue to be needing to pass the antiforgery token in with the request as a data option like so

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

and then in the JavaScript

function sendAntiForgery() {
        return { "__RequestVerificationToken": $('input[name=__RequestVerificationToken]').val() }
    }
0
Viktor Tachev
Telerik team
answered on 19 Apr 2019, 07:11 AM
Hi Simon,

I am glad that you have found what is causing the error. Indeed .NET Core requires an anti forgery token to be submitted with the request. Otherwise the request is not accepted. 

Thank you for sharing your solution. This can help someone facing similar error.


Regards,
Viktor Tachev
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Grid
Asked by
Simon
Top achievements
Rank 1
Answers by
Simon
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or