Product Bundles
DevCraft
All Telerik .NET and Kendo UI JavaScript components and AI Tools in one package.
Kendo UI
Bundle of AI Tools plus four JavaScript UI libraries built natively for jQuery, Angular, React and Vue.
Build JavaScript UI
Javascript
Agent and App Development Solutions
Build. Accelerate. Govern.
AI-Ready Application Experiences
AI-Assisted SDLC
Agent Governance and Control
Telerik
Build modern .NET business apps
.Net Web
Desktop
Reporting and Documents
Cross-Platform
Additional Tools
Enhance the developer and designer experience
Testing & Mocking
CMS
Debugging
UI Tools
Free Tools
Support and Learning
Productivity and Design Tools
Hello this is my Controller in my code I am trying to update or delete from the database. I get a 200 status which says its succesful but it never gets updated or deleted.I can read and create fine but updating is a little challenging.this is the response i get from the debbuger when i edit a row:Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished HTTP/1.1 POST https://localhost:57770/Grid/ClientsEdit/14416 application/x-www-form-urlencoded;+charset=UTF-8 176 - 200 - application/json;+charset=utf-8 683.0242mspublic ActionResult ClientsEdit(int id, ClientDatum clientDatum, [DataSourceRequest] DataSourceRequest request) { PrincipalContext pc = new PrincipalContext(ContextType.Domain, "WIX"); UserPrincipal up = UserPrincipal.FindByIdentity(pc, User.Identity.Name); GroupPrincipal ad = GroupPrincipal.FindByIdentity(pc, "Administrators"); GroupPrincipal gr = GroupPrincipal.FindByIdentity(pc, "Gr"); clientDatum = _clientContext.ClientData.Find(id); var clients = _clientContext.ClientData.ToList(); var dsClient = cleints.ToDataSourceResult(request); if (id == null) { return BadRequest(); } else if (gangDatum == null) { return NotFound(); } else if (User.Identity.IsAuthenticated && (up.IsMemberOf(ad) || up.IsMemberOf(gr))) { if (ModelState.IsValid) { _clientContext.ClientData.Update(clientDatum); _clientContext.Entry(clientDatum).State = EntityState.Modified; _clientContext.SaveChanges(); } return Json(clients); } else { string msg = "You need to authenticate to create a user"; return Json(msg); } }
Hello this is my Controller in my code I am trying to update or delete from the database.
I get a 200 status which says its succesful but it never gets updated or deleted.
I can read and create fine but updating is a little challenging.
this is the response i get from the debbuger when i edit a row:
public ActionResult ClientsEdit(int id, ClientDatum clientDatum, [DataSourceRequest] DataSourceRequest request) { PrincipalContext pc = new PrincipalContext(ContextType.Domain, "WIX"); UserPrincipal up = UserPrincipal.FindByIdentity(pc, User.Identity.Name); GroupPrincipal ad = GroupPrincipal.FindByIdentity(pc, "Administrators"); GroupPrincipal gr = GroupPrincipal.FindByIdentity(pc, "Gr");
clientDatum = _clientContext.ClientData.Find(id); var clients = _clientContext.ClientData.ToList(); var dsClient = cleints.ToDataSourceResult(request); if (id == null) { return BadRequest(); } else if (gangDatum == null) { return NotFound(); } else if (User.Identity.IsAuthenticated && (up.IsMemberOf(ad) || up.IsMemberOf(gr))) { if (ModelState.IsValid) { _clientContext.ClientData.Update(clientDatum); _clientContext.Entry(clientDatum).State = EntityState.Modified; _clientContext.SaveChanges(); } return Json(clients); } else { string msg = "You need to authenticate to create a user"; return Json(msg); } }
<div class="row"> <div class="col-12"> @(Html.Kendo().Grid <TelerikGangsApp.Models.ClientDatum>() .Name("grid") .Columns(columns => { //columns.Bound(p => p.Id); columns.Bound(p => p.FirstName); columns.Bound(p => p.MiddleName); columns.Command(command => command.Edit()).Width(150); columns.Command(command => command.Destroy()).Width(150); }) .ToolBar(toolbar => { toolbar.Create(); //toolbar.Save(); toolbar.Pdf(); toolbar.Search(); }) .Pdf(pdf => pdf //.AllPages() .AvoidLinks() .PaperSize("A1") .Margin("2cm", "1cm", "1cm", "1cm") .Landscape() .RepeatHeaders() .TemplateId("page-template") .FileName("Gangs.pdf") .ProxyURL(Url.Action("PdfExport", "Grid")) ) .Editable(editable => editable.Mode(GridEditMode.InLine)) .Pageable() .Sortable() .Scrollable() .Filterable() .Groupable() .HtmlAttributes(new { style = "height:550px;" }) .DataSource(dataSource => dataSource .WebApi() .Batch(false) .PageSize(20) .ServerOperation(false) .Model(model => { model.Id(client => client.Id); model.Field(client => client.Id).Editable(false); }) .Read(read => read.Action("ClientRead", "Grid").Type(HttpVerbs.Get)) .Create(create => create.Action("ClientCreate", "Grid").Type(HttpVerbs.Post)) .Update(update => update.Action("ClientsEdit", "Grid", new {id = "{0}"}).Type(HttpVerbs.Post)) .Destroy(destroy => destroy.Action("ClientDelete", "Grid", new {id = "{0}"}).Type(HttpVerbs.Post)) ) ) </div> </div>
Hello Andi,
Thank you for the shared code snippets.
To display the updated Grid data when a specified record is edited, it is required to return the respective record back to the client.
For example, when the Grid is bound in Web API, the Update operation returns the DataSourceResult object:
public ActionResult ClientsEdit(int id, ClientDatum clientDatum, [DataSourceRequest] DataSourceRequest request) { .... if (id == null) { return BadRequest(); } else if (gangDatum == null) { return NotFound(); } else if (User.Identity.IsAuthenticated && (up.IsMemberOf(ad) || up.IsMemberOf(gr))) { if (ModelState.IsValid) { _clientContext.ClientData.Update(clientDatum); _clientContext.Entry(clientDatum).State = EntityState.Modified; _clientContext.SaveChanges(); } return new ObjectResult(new DataSourceResult { Data = new[] { clientDatum }, Total = 1 }); } else { string msg = "You need to authenticate to create a user"; return Json(msg); } }
In addition, I am attaching a runnable sample for your convenience.
Hopefully, it will help you to resolve the issue.
Regards, Mihaela Progress Telerik
Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.
Hello this is my Controller in my code I am trying to update or delete from the database.
I get a 200 status which says its succesful but it never gets updated or deleted.
I can read and create fine but updating is a little challenging.
this is the response i get from the debbuger when i edit a row:
Microsoft.AspNetCore.Hosting.Diagnostics: Information: Request finished HTTP/1.1 POST https://localhost:57770/Grid/ClientsEdit/14416 application/x-www-form-urlencoded;+charset=UTF-8 176 - 200 - application/json;+charset=utf-8 683.0242ms<div class="row"> <div class="col-12"> @(Html.Kendo().Grid <TelerikGangsApp.Models.ClientDatum>() .Name("grid") .Columns(columns => { //columns.Bound(p => p.Id); columns.Bound(p => p.FirstName); columns.Bound(p => p.MiddleName); columns.Command(command => command.Edit()).Width(150); columns.Command(command => command.Destroy()).Width(150); }) .ToolBar(toolbar => { toolbar.Create(); //toolbar.Save(); toolbar.Pdf(); toolbar.Search(); }) .Pdf(pdf => pdf //.AllPages() .AvoidLinks() .PaperSize("A1") .Margin("2cm", "1cm", "1cm", "1cm") .Landscape() .RepeatHeaders() .TemplateId("page-template") .FileName("Gangs.pdf") .ProxyURL(Url.Action("PdfExport", "Grid")) ) .Editable(editable => editable.Mode(GridEditMode.InLine)) .Pageable() .Sortable() .Scrollable() .Filterable() .Groupable() .HtmlAttributes(new { style = "height:550px;" }) .DataSource(dataSource => dataSource .WebApi() .Batch(false) .PageSize(20) .ServerOperation(false) .Model(model => { model.Id(client => client.Id); model.Field(client => client.Id).Editable(false); }) .Read(read => read.Action("ClientRead", "Grid").Type(HttpVerbs.Get)) .Create(create => create.Action("ClientCreate", "Grid").Type(HttpVerbs.Post)) .Update(update => update.Action("ClientsEdit", "Grid", new {id = "{0}"}).Type(HttpVerbs.Post)) .Destroy(destroy => destroy.Action("ClientDelete", "Grid", new {id = "{0}"}).Type(HttpVerbs.Post)) ) ) </div> </div>