- Home
- Forum
- ASP.NET Core - EJ 2
- Datagrid, works for insert & delete but update fails to work with mongodb, value returns null.
Datagrid, works for insert & delete but update fails to work with mongodb, value returns null.
Here is my Grid Code
<ejs-grid id="Grid" height="272" allowPaging="true" allowSorting="true" dataBound="dataBound" allowFiltering="true" toolbar="@(new List<string>() { "Add", "Edit", "Delete","Update","Cancel" })" allowSelection="true" allowExcelExport="true" toolbarClick="toolbarClick">
<e-data-manager url="/Jobs/UrlDataSource" adaptor="UrlAdaptor" insertUrl="/Jobs/Insert" updateUrl="/Jobs/Update" removeUrl="/Jobs/Delete"></e-data-manager>
<e-grid-filterSettings type="Menu"></e-grid-filterSettings>
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog"></e-grid-editSettings>
<e-grid-selectionsettings type="Single"></e-grid-selectionsettings>
<e-grid-columns>
<e-grid-column type="checkbox" width="50"></e-grid-column>
<e-grid-column field="Job_id" headerText="Job_id" allowEditing="false"></e-grid-column>
<e-grid-column field="Requirements.Education" headerText="Education"></e-grid-column>
<e-grid-column field="Requirements.Experience" headerText="Experience"></e-grid-column>
<e-grid-column field="Requirements.Languages" headerText="Languages"></e-grid-column>
<e-grid-column field="Company.name" headerText="Company"></e-grid-column>
<e-grid-column field="Date_posted" headerText="Date_posted"></e-grid-column>
<e-grid-column field="Job_title" headerText="Job_title"></e-grid-column>
<e-grid-column field="Salary" headerText="Salary"></e-grid-column>
<e-grid-column field="Spoken_Languages" headerText="Spoken_Languages"></e-grid-column>
<e-grid-column field="Site_link" headerText="Site_link"></e-grid-column>
<e-grid-column field="Id" headerText="Id" isPrimaryKey="true" isIdentity="true"></e-grid-column>
</e-grid-columns>
</ejs-grid>
Here is my Update Function in my JobController
public ActionResult Update([FromBody]CRUDModel<Job> value)
{
var ord = value.Value;
Job val = _jobService.Get(value.Value.Id);
if (val == null)
{
return NotFound();
}
//val.Id = ord.Value.Id;
val.Requirements.Experience = ord.Requirements.Experience;
val.Requirements.Education = ord.Requirements.Education;
val.Requirements.Languages = ord.Requirements.Languages;
val.Company.name = ord.Company.name;
val.Date_posted = ord.Date_posted;
val.Job_title = ord.Job_title;
val.Salary = ord.Salary;
val.Job_id = ord.Job_id;
val.Spoken_Languages = ord.Spoken_Languages;
val.Site_link = ord.Site_link;
_jobService.Update(value.Value.Id, val);
return Json(value);
}
I have also provided a screenshot of the error and as you can see value is null.
SIGN IN To post a reply.
1 Reply
1 reply marked as answer
AG
Ajith Govarthan
Syncfusion Team
November 9, 2020 12:36 PM UTC
Hi Pieter,
Thanks for contacting Syncfusion support.
Query: I have provided a screenshot of the error and as you can see value is null.
Based on the attached code example we have prepared sample with URL DataAdaptor and Dialog edit mode at our end. In the prepared sample we did not face any mentioned issues at our end. For your convenience we have attached the sample so please refer the sample for your reference.
Code Example:
|
Index.cshtml
<ejs-grid id="Grid" allowPaging="true" load="onLoad" toolbar="@(new List<string>() {"Add", "Edit", "Update", "Delete" })">
<e-data-manager url="/Home/UrlDataSource" adaptor="UrlAdaptor" insertUrl="/Home/Insert" updateUrl="/Home/Update" removeUrl="/Home/Remove"></e-data-manager>
<e-grid-editSettings allowAdding="true" allowDeleting="true" allowEditing="true" mode="Dialog" ></e-grid-editSettings>
<e-grid-columns>
<e-grid-column type="checkbox" width="50"></e-grid-column>
<e-grid-column field="ShipCity" allowEditing="false" headerText="Ship City" width="150"></e-grid-column>
<e-grid-column field="OrderID" headerText="Order ID" isPrimaryKey="true" textAlign="Right" width="100"></e-grid-column>
<e-grid-column field="CustomerID" headerText="Customer ID" type="string" validationRules="@(new { required= true })" width="120"></e-grid-column>
<e-grid-column field="Freight" headerText="Freight" textAlign="Right" format="C2" editType="numericedit" width="120"></e-grid-column>
<e-grid-column field="Customer.Name" headerText="Name" width="150"></e-grid-column>
<e-grid-column field="Customer.CustomerId" headerText="ID" width="150"></e-grid-column> //complex binding
</e-grid-columns>
</ejs-grid>
<script>
function onLoad() {
this.dataSource.dataSource.headers = [{ 'XSRF-TOKEN': $("input:hidden[name='__RequestVerificationToken']").val() }];
}
</script> |
|
HomeController.cs
public IActionResult Update([FromBody]CRUDModel<Orders> model)
{
var data = order.Where(or => or.OrderID == model.Value.OrderID).FirstOrDefault();
if (data != null)
{
data.OrderID = model.Value.OrderID;
data.CustomerID = model.Value.CustomerID;
data.EmployeeID = model.Value.EmployeeID;
data.OrderDate = model.Value.OrderDate;
data.ShipCity = model.Value.ShipCity;
data.Freight = model.Value.Freight;
data.Customer.CustomerId = model.Value.Customer.CustomerId;
data.Customer.Name = model.Value.Customer.Name;
}
return Json(model.Value);
} |
Sample Link: https://www.syncfusion.com/downloads/support/directtrac/general/ze/UrlAdaptor-CRUD-NormatEdit_complex-1209036006.zip
UG-Links:
If you still face the issue, then please share the below details to validate further on your requirement.
- If possible, please try to reproduce the issue in the attached sample.
- Share the Syncfusion package version.
Regards,
Ajith G.
Marked as answer
SIGN IN To post a reply.