- Home
- Forum
- ASP.NET Core - EJ 2
- Razor Pages .Net 8 UrlAdaptor Not Posting on Page Handler
Razor Pages .Net 8 UrlAdaptor Not Posting on Page Handler
Hi all,
I am following exactly the example on posting to page handler with antiforgery token but is not working and i am getting error 400 Bad Request. I am facing the same problem on both in 26.x.x and 27.x.x versions. Using the 24.2.7 version works fine and I am sure about that because I have another project doing the same thing with v24.2.7 and is working. On this project with either 26.x.x or 27.x.x not working. Any suggetions? Following is my code:
index.cshtml
@{
string fullUrl = $"{Request.Scheme}://{Request.Host}{Request.PathBase}{Request.Path}";
}
@Html.AntiForgeryToken()
<ejs-grid id="usersGrid"
allowPaging="true"
allowSorting="true"
allowFiltering="true"
allowExcelExport="false"
allowPdfExport="false"
toolbar="@(new List<string>() { "Search", "ColumnChooser" })"
showColumnChooser="true"
load="onGridLoad">
<e-grid-loadingIndicator indicatorType="Shimmer"></e-grid-loadingIndicator>
<e-grid-selectionsettings type="Single"></e-grid-selectionsettings>
<e-grid-pagesettings pageSize="10"></e-grid-pagesettings>
<e-data-manager url="@fullUrl?handler=FetchUsers" adaptor="UrlAdaptor"></e-data-manager>
<e-grid-columns>
<e-grid-column field="UserId" headerText="User ID" isPrimaryKey="true" textAlign="Left" width="200"></e-grid-column>
<e-grid-column field="PartnerType" headerText="PartnerType" width="100"></e-grid-column>
<e-grid-column field="Username" headerText="Username" width="150"></e-grid-column>
<e-grid-column field="GivenName" headerText="GivenName" width="150"></e-grid-column>
<e-grid-column field="DateOfBirth" headerText="DateOfBirth" textAlign="Right" customFormat="@(new {type = "datetime", format = "dd/MM/yyyy" })" width="100"></e-grid-column>
<e-grid-column field="PhoneNumber" headerText="PhoneNumber" textAlign="Right" format="C2" width="140"></e-grid-column>
<e-grid-column field="TwoFactorEnabled" headerText="TwoFactorEnabled" textAlign="Center" displayAsCheckBox="true" type="boolean" width="80"></e-grid-column>
<e-grid-column field="LastLogin" headerText="LastLogin" textAlign="Right" customFormat="@(new {type = "datetime", format = "dd/MM/yyyy" })" width="100"></e-grid-column>
<e-grid-column field="Status" headerText="Status" textAlign="Center" width="80" template="#statusTemplate"></e-grid-column>
<e-grid-column headerText="" textAlign="Center" width="110" commands="commands"></e-grid-column>
</e-grid-columns>
</ejs-grid>
@section PageScripts {
<script type="text/javascript" asp-append-version="true">
// Grid onload event to send anti-forgery token on every request.
function onGridLoad() {
this.dataSource.dataSource.headers = [{ 'X-CSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val() }];
};
</script>
}
index.cshtml.cs
public async Task<JsonResult> OnPostFetchUsersAsync([FromBody] DataManagerRequest dm)
{
PagingInformation resultPI;
List<UsersListViewModel> users;
(users, resultPI) = await _siteAdministrationService.GetUsersListAsync(dm);
return new JsonResult(new { result = users, count = resultPI.TotalRecordCount });
}
Hi Thomas,
Greetings from Syncfusion support,
We understand that you are facing an issue with antiforgery token sample. We have tested the reported scenario with the latest version (27.1.50) and were unable to replicate the issue. The setup works as expected with no issues encountered. Please refer to the below screenshot and sample for information,
|
|
We recommend using the provided sample as a reference to resolve the issue you mentioned. If the issue persists, provide the issue reproducible sample or try reproducing the issue in the sample we shared.
Regards,
Vikram S
Attachment: core_razor_grid_urlAdaptor_51ed17bc.zip
- 1 Reply
- 2 Participants
-
TH Thomas
- Sep 29, 2024 03:43 PM UTC
- Sep 30, 2024 01:00 PM UTC