Good evening everybody
Situation:
At the moment I'm struggling for hours at the following issue based on: https://ej2.syncfusion.com/aspnetcore/documentation/grid/how-to/perform-crud-operation-using-anti-forgery-token/?_ga=2.187400363.2067813694.1574268221-2069559230.1571128166#perform-crud-operation-using-anti-forgery-token
Everytime when I create an entry over the create dialog. It will be added as an empty row without data. From the server perspective everything is fine. It is saved within the database and after a reload of the page the entry will appear correctly. But how can i solve this issue without reloading the page or adding an action as datasource. I really want to go the lean MVC way.
CSHTML:
--> I had issues with pasting in the code.
Controller:
[HttpGet]
public async Task Index()
{
var model = await Db.Doctors.OrderBy(m => m.Lastname).ToListAsync();
return View(model);
}
[HttpPost]
[ValidateAntiForgeryToken]
public async Task
Insert(Doctor value) {
await Db.Doctors.AddAsync(value);
await Db.SaveChangesAsync();
return Json(value);
}
Doctor Class:
public class Doctor
{
public int Id { get; set; }
[Required]
public string Firstname { get; set; }
[Required]
public string Lastname { get; set; }
}
Insert Action Response example:
{"id":21,"firstname":"test","lastname":"test"}
Javascript:
My javascript code looks exactly the same as that one suggested on: