I am having the same problem.
I think you guys at Synfusion missed the fact that this is "Razor Pages" in Core 2.0. Razor Pages support multiple "Handlers". Please look at: https://docs.microsoft.com/en-us/aspnet/core/mvc/razor-pages/?tabs=visual-studio#customizing-routing
For some reason, the post method on the Razor Page never gets called.
The problem is probably due to the fact that razor pages automatically check for the RequestVerificationToken, assuming a form-driven post. I found it necessary to do the following:
1. Add a property & constructor to the pagemodel to receive the anti-forgery injection:
public IAntiforgery Xsrf { get; private set; }
public MyPageModel(IAntiforgery xsrf)
{
Xsrf = xsrf;
}
2. Declare a property on the pages' codebehind:
public List
{
get
{
var hdr = new List
var dict = new Dictionary
{
["RequestVerificationToken"] = Xsrf.GetAndStoreTokens(HttpContext).RequestToken
};
hdr.Add(dict);
return hdr;
}
}
3. In the datamanager tag helper, add a "headers" attribute:
remove-url="/Content/Remove"
update-url="/Content/Update"
adaptor="remoteSaveAdaptor"
headers=@Model.Headers />
This will send the token as part of the header to any of the CRUD requests, and you should see the handlers firing.
@page "{handler?}"
@model IndexModel
<ej-grid id="FlatGrid" query="new ej.Query()">
<e-datamanager url="DataSource" adaptor="UrlAdaptor" headers='new List<Dictionary<string,object>> { new Dictionary<string, object>() { { "XSRF-TOKEN", "YOUR ANTI FORGERY TOKEN HERE" } } }'></e-datamanager>
<e-columns>
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
</e-columns>
</ej-grid> |
[ValidateAntiForgeryToken]
public ActionResult OnPostDataSource()
{
. . . . . . . . . . . . . . . . . . . . . . . . . .
} |
Hi Brian,The support incident has been created under your account for your reported query. Please log on to our support website to check for further updates.Regards,Saravanan A.
<div style="padding:20px;">
<ej-grid id="FlatGrid" allow-paging="true">
<e-datamanager json="@Model.TestModel.Orderdata" update-url="NormalUpdate" insert-url="NormalInsert" remove-url="NormalDelete" adaptor="remoteSaveAdaptor" />
<e-columns>
<e-column field="OrderID" header-text="Order ID" is-primary-key="true" text-align="Right" width="75"></e-column>
<e-column field="CustomerID" header-text="Customer ID" width="80"></e-column>
. . .
</e-columns>
</ej-grid>
</div>
public class IndexModel : PageModel
{
[BindProperty]
public TestModel TestModel { get; set; }
public void OnGet(){
GetDataSource();
}
public IActionResult OnPost(TestModel value){
. . .
}
public void GetDataSource(){
TestModel.Orderdata.Add(new Order(code + 1, "ALFKI", i + 0, 2.3 * i, new DateTime(1991, 05, 15), "Berlin"));
TestModel.Orderdata.Add(new Order(code + 2, "ANATR", i + 2, 3.3 * i, new DateTime(1990, 04, 04), "Madrid"));
}
}
}
public class Order
{
public Order()
{
}
. . .
}
}
|