- Home
- Forum
- ASP.NET MVC
- Update Row after server has updatet the Data
Update Row after server has updatet the Data
Hi All I'm using the ASP.NET MVC Grid => @(Html.EJ().Grid<object>("FlatGrid") and I'm the EditorTemplate for changing data. After the Update the UpdateURL will be called where calculate the Price column. But when I send the return the price column is not updateing.
as return I tried the following
return Json(LoadGridData(), JsonRequestBehavior.AllowGet);
return Json(value, JsonRequestBehavior.AllowGet);return View();
return View("Index");
I have changed the value parameter and I have updatet the ViewBag.datasource
Can you please tell me what I'm doing wrong.
Regards Michael
Controller
public ActionResult ExternalUpdate(BookingVM value)
{
if (value.Pax == 0 && value.Price > 0)
return Json(value, JsonRequestBehavior.AllowGet);
ApplicationDbContext db = new ApplicationDbContext();
var bookings = db.Bookings.Include("Station").Where(b => b.BookingID == value.BockingID).ToList();
if(bookings.Count != 1)
return Json(new { status = "error", message = "error creating customer" });
var booking = bookings[0];
booking.Address = value.Address;
booking.EMail = value.EMail;
booking.Name = value.Name;
if (booking.Pax != value.Pax)
{
booking.Pax = value.Pax;
if (booking.Station != null)
{
booking.Price = booking.Station.Price * booking.Pax;
value.Price = booking.Price;
}
}
booking.State = value.State;
booking.Telephone = value.Telephone;
db.Entry(booking).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
ViewBag.datasource = LoadGridData();
return Json(LoadGridData(), JsonRequestBehavior.AllowGet);
}
Grid
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource(
ds => ds.Json((IEnumerable<object>)ViewBag.dataSource)
.UpdateURL("/Home/ExternalUpdate")
.InsertURL("/Home/ExternalInsert")
.Adaptor(AdaptorType.RemoteSaveAdaptor)
)
.AllowScrolling()
.AllowFiltering()
.FilterSettings(filter => { filter.ShowFilterBarStatus().StatusBarWidth(500).FilterBarMode(FilterBarMode.Immediate); })
.AllowSorting()
.AllowGrouping()
.GroupSettings(group => { group.ShowDropArea(false).ShowGroupedColumn(false).EnableDropAreaAnimation(false).GroupedColumns(col => { col.Add("Tour"); col.Add("Bus"); col.Add("Station"); }); }) /*Grouping Enabled for UniversityCode */
.SelectionType(SelectionType.Single)
.AllowResizing()
.IsResponsive().ClientSideEvents(evt =>
{
evt.QueryCellInfo("OnQueryCellInfo");
evt.RowDataBound("rowDataBound");
evt.ActionComplete("editdone");
})
.EditSettings(e => e.AllowAdding(true).AllowEditing(true).EditMode(EditMode.DialogTemplate).DialogEditorTemplateID("#template"))
.Columns(col =>
{
col.Field("Tour").HeaderText("Tour").TextAlign(TextAlign.Left).Width(100).Add();
col.Field("Bus").HeaderText("Bus").TextAlign(TextAlign.Left).Width(100).Add();
col.Field("Station").HeaderText("Haltestelle").TextAlign(TextAlign.Left).Width(100).Add();
col.Field("Name").HeaderText("Name").TextAlign(TextAlign.Left).Width(120).CssClass("customizesXXX").Add();
col.Field("Address").HeaderText("Anschrift").TextAlign(TextAlign.Left).Width(120).CssClass("customizes").Add();
col.Field("Telephone").HeaderText("Telefon").TextAlign(TextAlign.Left).Width(120).Add();
col.Field("EMail").HeaderText("E-Mail").TextAlign(TextAlign.Left).Width(150).Add();
col.Field("Pax").HeaderText("Pax").TextAlign(TextAlign.Center).Width(70).Add();
col.Field("Price").HeaderText("Preis").TextAlign(TextAlign.Right).Format("{0:C}").Width(90).Add();
col.Field("State").HeaderText("Status").TextAlign(TextAlign.Center).Width(100).EditType(EditingType.Dropdown).Add();
col.Field("SinglePrice").HeaderText("SinglePrice").TextAlign(TextAlign.Center).Width(100).Visible(false).Add();
col.Field("BockingID").HeaderText("BockingID").IsPrimaryKey(true).TextAlign(TextAlign.Left).Width(0).Visible(false).Add();
}
))
SIGN IN To post a reply.
8 Replies
MP
Manivannan Padmanaban
Syncfusion Team
March 15, 2018 01:15 PM UTC
Hi Michael,
Thanks for contacting syncfusion support.
We have analyzed your query and we are able to understand that your facing the issue while updating the expression column value from server side in remote save adaptor we are unable to reproduce the reported issue at our end please refer the below code example,
|
@(Html.EJ().Grid<object>("FlatGrid")
.Datasource(ds => ds.Json((IEnumerable<object>)ViewBag.datasource).UpdateURL("/Grid/Update")
.InsertURL("/Grid/Insert").RemoveURL("/Grid/Remove").Adaptor(AdaptorType.RemoteSaveAdaptor))
…..
.Columns(col =>
{
col.Field("OrderID").IsPrimaryKey(true).AllowEditing(true).Add();
col.Field("EmployeeID").AllowEditing(true).Add();
col.Field("Freight").AllowEditing(true).Add();
})
)
// Controller page
public ActionResult Insert(EditableOrder value)
{
if (value.EmployeeID > 6)
{
value.Freight = value.EmployeeID * value.OrderID;
OrderRepository.Update(value); // update the value
return Json(value, JsonRequestBehavior.AllowGet);
}
else
OrderRepository.Add(value);
var data = OrderRepository.GetAllRecords();
return Json(data, JsonRequestBehavior.AllowGet);
}
|
For your convenience we have created the sample please refer to the below link to download the sample,
Please get back to us, if you need further assistance.
Regards,
Manivannan Padmanaban.
MK
Michael Kroeschel
March 15, 2018 01:54 PM UTC
Hi
Manivannan
the difference
between your and my code was that my columns where not set to
.AllowEditing(true). After I changed that the Grid Removed the complete row after he came
back from the Server.
Any Idea what that can be?
Regards
MK
Michael Kroeschel
March 16, 2018 07:23 AM UTC
Hi Manivannan
I have implemented now also the add new functionality and there I have the same problem that the gird is not showing the Data from the columns I have changed on server side. In this case these are all columns where I made a grouping on.
I also played a bit around with the result Values.
As you suggested I used => return Json(value, JsonRequestBehavior.AllowGet); But when I return a Json with the complete List or just the one changed Dataset the Grid is doing nothing. It isn't even adding the new one!?!?!?
What I tried is, that I send him back to Index where I rebuild the complete Viewback.datasoure. But I get the result that the Grid is only showing the Data I have added on Client side.
When I hit f5 the Grid reloads the data and it looks good?!?!?!
Can you please help I'm a bit under pressure here.
Thank you for your help
Regards
Michael
MK
Michael Kroeschel
March 16, 2018 07:35 AM UTC
Hi Manivannan
can you please close this case! I do not know why but know the return Json(value, JsonRequestBehavior.AllowGet); works!?!?!
Thanks for your help
Michael
MP
Manivannan Padmanaban
Syncfusion Team
March 16, 2018 02:32 PM UTC
Hi Michael,
Thanks for the update.
Query: I do not know why but know the return Json(value, JsonRequestBehavior.AllowGet); works!?!?!
Refer the below code example, we have update the expression column value (i.e. Freight ) value in the value parameter . So, you need to return the value parameter.
|
// Controller page
public ActionResult Insert(EditableOrder value)
{
if (value.EmployeeID > 6)
{
value.Freight = value.EmployeeID * value.OrderID;
OrderRepository.Update(value); // updated the column value in value parameter
return Json(value, JsonRequestBehavior.AllowGet);
}
else
OrderRepository.Add(value);
var data = OrderRepository.GetAllRecords();
return Json(data, JsonRequestBehavior.AllowGet);
}
|
Regards,
Manivannan Padmanaban.
MP
Manivannan Padmanaban
Syncfusion Team
March 16, 2018 02:36 PM UTC
Hi Michael,
Thanks for the update.
Query: I do not know why but know the return Json(value, JsonRequestBehavior.AllowGet); works!?!?!
Refer the below code example, we have update the expression column value (i.e. Freight ) value in the value parameter . So, you need to return the value parameter.
|
// Controller page
public ActionResult Insert(EditableOrder value)
{
if (value.EmployeeID > 6)
{
value.Freight = value.EmployeeID * value.OrderID;
OrderRepository.Update(value); // updated the column value in value parameter
return Json(value, JsonRequestBehavior.AllowGet);
}
else
OrderRepository.Add(value);
var data = OrderRepository.GetAllRecords();
return Json(data, JsonRequestBehavior.AllowGet);
}
|
Regards,
Manivannan Padmanaban.
MK
Michael Kroeschel
March 20, 2018 09:53 AM UTC
Hi Manivannan
thank you for your help! return Json(value, JsonRequestBehavior.AllowGet); works know.
Regards
Michael
FS
Farveen Sulthana Thameeztheen Basha
Syncfusion Team
March 21, 2018 07:27 AM UTC
Hi Michael,
Thanks for your update. Please get back to us if you need any further assistance.
Regards,
Farveen sulthana T
SIGN IN To post a reply.
- 8 Replies
- 3 Participants
-
MK Michael Kroeschel
- Mar 13, 2018 08:39 PM UTC
- Mar 21, 2018 07:27 AM UTC