Here is the controller data: (Full code attached)
public ActionResult GetData(Syncfusion.JavaScript.DataManager dm) {
System.Collections.IEnumerable Data = db.Requests.ToList();
sgDataResult result = new sgDataResult();
Syncfusion.JavaScript.DataSources.DataOperations operation = new Syncfusion.JavaScript.DataSources.DataOperations();
if (dm.Sorted != null && dm.Sorted.Count > 0) //Sorting
Data = operation.PerformSorting(Data, dm.Sorted);
if (dm.Where != null && dm.Where.Count > 0) //Filtering
Data = operation.PerformWhereFilter(Data, dm.Where, dm.Where[0].Operator);
if (dm.Search != null && dm.Search.Count > 0) //searching
Data = operation.PerformSearching(Data, dm.Search);
List<string> str = new List<string>();
if (dm.Aggregates != null)
{
for (var i = 0; i < dm.Aggregates.Count; i++)
str.Add(dm.Aggregates[i].Field);
result.aggregate = operation.PerformSelect(Data, str);
}
int count = Data.AsQueryable().Count();
if (dm.Skip != 0)
Data = operation.PerformSkip(Data, dm.Skip);
if (dm.Take != 0)
Data = operation.PerformTake(Data, dm.Take);
result.count = count;
result.result = Data;
return Json(result, JsonRequestBehavior.AllowGet);
}
public ActionResult Insert(Request value) {
value.Created = DateTime.Now;
value.CreatedBy = ((AuthUser)Session["user"]).Name;
value.ISChoice = "OneCloud";
db.Requests.Add(value);
value of value.RequestID (which is the PK) = 0 - which is correct at this time try
{
db.SaveChanges();
after SaveChanges the value of value.RequestID(PK) should be updated to the new PK value but it's still 0 }
catch (Exception ex)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Database Error: " + ex.Data);
}
return Json(value, JsonRequestBehavior.AllowGet);
}
View Data @(Html.EJ().Grid<Request>("OneCloudGrid")
.Datasource(ds => ds.URL(@Url.Action("GetData", "AdminOC")).UpdateURL(@Url.Action("Update", "AdminOC")).InsertURL(@Url.Action("Insert", "AdminOC")).Adaptor(AdaptorType.UrlAdaptor))
.EditSettings(edit => { edit.AllowEditing().AllowAdding(); })
.AllowScrolling(true)
.AllowPaging(true)
.
.
.
.
.Columns(col =>
{
col.Field(p => p.RequestID).HeaderText("Request ID").AllowEditing(false).IsIdentity(true).IsPrimaryKey(true).TextAlign(TextAlign.Center).Width(93).Add();
col.Field(p => p.Period).HeaderText("Period").Width(82).TextAlign(TextAlign.Center).EditType(EditingType.Dropdown).DataSource(Model.ddlists.nsPeriod).Add();
Attachment:
Code_720aa7c4.zip