- Home
- Forum
- ASP.NET Core - EJ 2
- How can I save dialog editing changes to the database using local data type datasource?
How can I save dialog editing changes to the database using local data type datasource?
I am trying to save editing changes done in dialog edit box in database but its not updating in database.
If possible can you please provide example for to better understanding.
Also if not possible with local database option can you please provide example of urladapter/datamanager as I am not able to understand through example provided in documentation
How can I Bind datatable as datasource in datamanager?
Hi Khushi Patel,
Greetings from Syncfusion support.
We have validated your query and understand that you need assistance with handling grid dialog editing CRUD operations using URL adaptor data binding. We have prepared a sample for your reference. In the sample, we used DataManager URL adaptor as the grid's data source and handled server CRUD operations for the grid's dialog editing using DataManager URL adaptor. Please refer to the below code example, API documentation, and sample for more details.
[code example]
|
Cshtml code example
<ejs-grid id="Grid" allowPaging="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })"> <e-grid-editsettings allowEditing="true" allowDeleting="true" allowAdding="true" mode="Dialog"></e-grid-editsettings> <e-grid-pagesettings pageCount="4" ></e-grid-pagesettings> <e-data-manager url="/Home/UrlDatasource" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Delete" adaptor="UrlAdaptor"></e-data-manager> <e-grid-columns> . . . . . . . </e-grid-columns> </ejs-grid>
Home Controller code example
public IActionResult UrlDatasource([FromBody] DataManagerRequest dm) // requested by datamanager url adaptor url. {
IEnumerable DataSource = orddata.ToList(); DataOperations operation = new DataOperations();
if (dm.Search != null && dm.Search.Count > 0) { DataSource = operation.PerformSearching(DataSource, dm.Search); //Search } if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting { DataSource = operation.PerformSorting(DataSource, dm.Sorted); } if (dm.Where != null && dm.Where.Count > 0) //Filtering { DataSource = operation.PerformFiltering(DataSource, dm.Where, dm.Where[0].Operator); } int count = DataSource.Cast<OrdersDetails>().Count(); if (dm.Skip != 0) { DataSource = operation.PerformSkip(DataSource, dm.Skip); //Paging } if (dm.Take != 0) { DataSource = operation.PerformTake(DataSource, dm.Take); //Paging } return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource); }
public IActionResult Update([FromBody] CRUDModel<OrdersDetails> myObject) // requested by datamanager url adaptor update url. { var ord = myObject; OrdersDetails val = orddata.Where(or => or.OrderID == ord.Value.OrderID).FirstOrDefault(); // getting primary key matching data. if (val != null) { val.OrderID = ord.Value.OrderID; val.EmployeeID = ord.Value.EmployeeID; val.CustomerID = ord.Value.CustomerID; val.Freight = ord.Value.Freight; val.OrderDate = ord.Value.OrderDate; val.ShipCity = ord.Value.ShipCity; val.ShipAddress = ord.Value.ShipAddress; val.ShippedDate = ord.Value.ShippedDate; val.ShipCountry = ord.Value.ShipCountry; val.Verified = ord.Value.Verified; }
return Json(ord.Value);
} public IActionResult Insert([FromBody] CRUDModel<OrdersDetails> value) // requested by datamanager url adaptor insert url. { var ord = value; orddata.Insert(0, ord.Value); // Insert Record return Json(value.Value); } public IActionResult Delete([FromBody] CRUDModel<OrdersDetails> value) // requested by datamanager url adaptor remove url. { int key; if (int.TryParse(value.Key.ToString(), out key)) { orddata.Remove(orddata.Where(or => or.OrderID == key).FirstOrDefault()); // Delete record by matching primary key value. } return Json(value); } |
Sample: please find the attachment.
API documentations: Class CRUDModel<T> - API Reference (syncfusion.com) , Class DataManagerRequest - API Reference (syncfusion.com)
Regards,
Vasanthakumar K
Attachment: 187044dialogeditcrudurlcore_a597f418.zip
Hello Vasanthakumar,
Thank you for your reply.
But after having trouble with this adaptor we switched to RemoteSaveAdaptor as using this (url adaptor) enum values are shown as int.
Only problem we have with remote save is on update request data are posted null in method.
And also can you please provide example for this in Asp.net core razor format.
I am attaching the code below for Remote save can you please advise what is wrong with the code?
@page "{handler?}"
@model ThinkSense.LicenseManager.Pages.ActiveLicencesModel
@{
ViewBag.dataSource = Model.userList.ToArray();
}
@Html.AntiForgeryToken()
<div id="collapseOne" class="accordion-collapse collapse show " aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body p-0">
<div class="card-body gridview-height">
<ejs-grid id="grid" allowPaging="true" load="onLoad1" dataBound="GridDataBound" allowSorting="true" actionComplete="actionComplete" actionBegin="actionBegin" toolbar="@(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" })">
<e-data-manager json="@ViewBag.dataSource" adaptor="RemoteSaveAdaptor" updateUrl="/ActiveLicences?handler=Update"></e-data-manager>
@* <e-data-manager url="/ActiveLicences?handler=Update" adaptor="UrlAdaptor"></e-data-manager> *@
@* <e-data-manager url="/ActiveLicences?handler=UrlDatasource" adaptor="UrlAdaptor"></e-data-manager> *@
<e-grid-editsettings allowediting="true" allowAdding="true" mode="Dialog"></e-grid-editsettings>
<e-grid-pagesettings pagecount=4 pagesize=10></e-grid-pagesettings>
<e-grid-columns>
<e-grid-column field="EntryID" headerText="No." width="60px"></e-grid-column>
<e-grid-column field="EntryID" headerText="EntryID" visible=false AllowEditing=false IsIdentity="true" isPrimaryKey="true"></e-grid-column>
<e-grid-column field="UserAccountName" headerText="UserAccountName" width="150px"></e-grid-column>
<e-grid-column field="LicenseKey" headerText="LicenseKey" visible=false AllowEditing=false></e-grid-column>
<e-grid-column field="LicenseType" headerText="LicenseType" editType="dropdownedit"></e-grid-column>
<e-grid-column field="ExpiryDate" headerText="ExpiryDate" editType="datepickeredit" format="yyyy-MM-dd hh:mm"></e-grid-column>
<e-grid-column field="NumberOfUsers" headerText="NumberOfUsers" visible="false"></e-grid-column>@* format="###.##" *@
<e-grid-column field="PublicKey" headerText="PublicKey" visible=false></e-grid-column>
<e-grid-column field="PrivateKey" headerText="PrivateKey" visible=false></e-grid-column>
<e-grid-column field="AllowOverflow" headerText="AllowOverFlow" editType="dropdownedit"></e-grid-column>
<e-grid-column field="ProductName" headerText="ProductName" editType="dropdownedit"></e-grid-column>
<e-grid-column field="PingType" headerText="PingType" visible=false editType="dropdownedit"></e-grid-column>
<e-grid-column field="ProductFeatures" headerText="ProductFeatures"></e-grid-column>
<e-grid-column field="ExtraInfo1" headerText="ExtraInfo1" visible=false></e-grid-column>
<e-grid-column field="ExtraInfo2" headerText="ExtraInfo2" visible=false></e-grid-column>
<e-grid-column field="ExtraInfo3" headerText="ExtraInfo3" visible=false></e-grid-column>
<e-grid-column field="StartDate" headerText="StartDate" editType="datepickeredit" format="yyyy/MM/dd hh:mm:ss" width="150px"></e-grid-column>
<e-grid-column field="action" headertext="Action" template="#temp"> </e-grid-column>
</e-grid-columns>
</ejs-grid>
</div>
</div>
</div>
public List<UserAccounts> userList = DataController.FillData();
public IActionResult OnGet()
{
UserAccounts.BindcountData();
return Page();
}
public IActionResult OnPostUpdate([FromBody] UserAccounts value)
{
//Here you can Update a record based on your scenario
//return new JsonResult("@LicenseType", UserAccounts.LicenseType);
//return Page();
return new JsonResult(value);
}
Hi Khushi Patel,
Greetings from Syncfusion support.
We have validated your query and understand that you are facing a null value post for the grid's datamanager remote save adaptor data binding update URL. We have prepared a sample with a razor page and checked at our end, but the issue did not replicate. You can refer to the sample below with a razor page. Additionally, we noticed that in your update URL, there is no controller name available on that link, and also in your OnPostUpdate action, you are using a custom model UserAccounts from the body, but we are sending a request as a CRUDModel<T> type. You can refer to that custom model on that CRUDModel and also retrieve data from the Value property of CRUDModel. Therefore, we suspect those are the reasons for the null value on the server side. Kindly ensure this from your side as well. If you are still facing the issue, kindly provide the following details to assist us:
1) Share your complete grid rendering customization code including event handling (like load, actionBegin, dataBound, and actionComplete, etc.) and property updates (like column template, etc.).
2) Please share any reproducible sample of the issue or try to reproduce the issue with our shared sample.
3) Based on the provided information, we noticed that your Syncfusion package version is 24.2.8. Please confirm if this is correct.
4) Share the full procedure for replicating the issue or provide a video demonstration.
5) Please confirm if our understanding of the issue is correct.
Sample: Please find the attachment.
Attachment: 187091,187044razorpageremotesaveadaptorupdate_262cf0b7.zip
- 4 Replies
- 2 Participants
-
KP Khushi Patel
- Mar 4, 2024 11:16 AM UTC
- Mar 11, 2024 10:27 AM UTC