- Home
- Forum
- ASP.NET MVC
- Use Grid for editing entity children items
Use Grid for editing entity children items
{
public Community()
{
this.ContactCollection = new HashSet<Contact>();
this.AddressCollection = new HashSet<Address>();
this.AdditionInfoCollection = new HashSet<AdditionInfo>();
}
public long Id { get; set; }
public virtual ICollection<Contact> ContactCollection { get; set; }
public virtual ICollection<AdditionInfo> AdditionInfoCollection { get; set; }
}
{
public Address()
{
this.CommunityCollection = new HashSet<Community>();
this.AdditionInfoCollection = new HashSet<AdditionInfo>();
}
public int AddressId { get; set; }
public string Street { get; set; }
public string City { get; set; }
public string Country { get; set; }
public string HomeData { get; set; }
public string GpsX { get; set; }
public string GpsY { get; set; }
public virtual ICollection<Community> CommunityCollection { get; set; }
public virtual ICollection<AdditionInfo> AdditionInfoCollection { get; set; }
}
.Datasource(ds => ds.Json(Model.AdressesCollection.AsEnumerable<object>())
.UpdateURL("Community/AddressesListUpdate")
.RemoveURL("Community/AddressesListRemove")
.InsertURL("Community/AddressesListInsert").Adaptor(AdaptorType.RemoteSaveAdaptor))
.AllowScrolling()
.AllowFiltering()
.FilterSettings(filter => { filter.ShowFilterBarStatus().StatusBarWidth(500).FilterBarMode(FilterBarMode.Immediate); }) /*Filtering Enabled*/
.AllowSorting() /*Sorting Enabled*/
.AllowPaging() /*Paging Enabled*/
.SelectionType(SelectionType.Multiple)
.AllowResizing()
.ClientSideEvents(eve => { eve.ActionBegin("AddressesGridBeginAction"); })
.EditSettings(edit => edit.AllowAdding().AllowDeleting().AllowEditing())
.ToolbarSettings(toolbar =>
{
toolbar.ShowToolbar().ToolbarItems(items =>
{
items.AddTool(ToolBarItems.Add);
items.AddTool(ToolBarItems.Edit);
items.AddTool(ToolBarItems.Delete);
items.AddTool(ToolBarItems.Update);
items.AddTool(ToolBarItems.Cancel);
});
})
.Columns(col =>
{
col.Field("AdressId").HeaderText("Id").IsPrimaryKey(true).IsIdentity(true).Width(90).Add();
col.Field("Street").HeaderText("Street").Add();
col.Field("City").HeaderText("City").Add();
col.Field("Country").HeaderText("Country").Add();
}))
Hi Egor,
Thanks for using Syncfusion products.
You can pass the additional key values using the Headers of the ejDataManager. While performing update (save) action in the actionBegin event, add the required number of array of objects into Headers and retrieve them using the Request object of the HttpRequestMessage.
Refer to the below code example,
|
@(Html.EJ().Grid<object>("FlatGrid") .Datasource(ds => ds.Json((System.Collections.IEnumerable)ViewBag.DataSource).UpdateURL("/Home/Update").InsertURL("/Home/Insert").RemoveURL("/Home/Delete").Adaptor(AdaptorType.RemoteSaveAdaptor)) .ClientSideEvents(events => { events.ActionComplete("complete").ActionBegin("begin"); }) ) <script type="text/javascript"> var id = @Model.Id; //Getting ID from Model, considering Model as Community object. function begin(args) { if (args.requestType == 'save') { args.model.dataSource.dataSource.headers = []; args.model.dataSource.dataSource.headers.push({ "communityId": id }); //adding additional parameter to datamanager header } } function complete(args) { if (args.requestType == 'save') args.model.dataSource.dataSource.headers = [];//to avoid headers value to be interfered with other actions, emptied the Headers } </script> public ActionResult Update(List<EditableOrder> value) { int obj = Int32.Parse(Request.Headers.GetValues("communityId")[0]); //additional parameter communitId . . . . . . . . return Json(data, JsonRequestBehavior.AllowGet); } |
From your code example, we found that you are using Community object in Model. So, we are directly getting the community ID from Model.
We have already discussed about sending custom headers to the server in the following KB,
https://www.syncfusion.com/kb/5966/how-to-send-custom-headers-to-server-using-datamanager
Regards,
Gowthami V.
We are happy to hear that the solution meets your requirement. Please let us know if you need any further assistance.
Regards,
Seeni Sakthi Kumar S.
- 3 Replies
- 3 Participants
-
EG egor
- Jan 28, 2016 02:16 PM UTC
- Feb 1, 2016 05:58 AM UTC