We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

CRUD POST and entity framework

Hello nice to meet you. They will have an example about a crud where the parameters are sent by post.
Regards!

1 Reply

PS Pavithra Subramaniyam Syncfusion Team March 11, 2019 08:40 AM UTC

Hi José, 
 
Thanks for contacting Syncfusion support. 
 
Based on your requirement we have prepared a sample in which we have send the additional parameters with the server “POST” request. You can achieve this by using the “addParams” method in the “grid.query” property. Please refer to the below code example, documentation link and sample link for more information. 
 
[index.cshtml] 
@Html.EJS().Grid("Grid").DataSource(ds => ds.Url("/Home/UrlDataSource").UpdateUrl("/Home/Update").InsertUrl("/Home/Insert").RemoveUrl("/Home/Remove").Adaptor("UrlAdaptor")).Columns(col => 
{ 
    col.Field("OrderID").HeaderText("Order ID").IsPrimaryKey(true).Width("120").TextAlign(Syncfusion.EJ2.Grids.TextAlign.Right).Add(); 
    col.Field("CustomerID").HeaderText("Customer Name").Width("150").Add(); 
    .  .  . 
}).Query("new ej.data.Query().addParams('ej2Grid', 'true')").AllowPaging().EditSettings(edit => { edit.AllowAdding(true).AllowEditing(true).AllowDeleting(true); }).Toolbar(new List<string>() { "Add", "Edit", "Delete", "Update", "Cancel" }).Render() 
 
 
[controller.cs] 
 
namespace mvc_ej2.Controllers 
{ 
    public class HomeController : Controller 
    { 
        public ActionResult UrlDatasource(TestDm dm) 
        { 
             
            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); 
            } 
            return dm.RequiresCounts ? Json(new { result = DataSource, count = count }) : Json(DataSource); 
        } 
        public ActionResult Update(CRUDModel myObject) 
        { 
            var ord = myObject.Value; 
            OrdersDetails val = orddata.Where(or => or.OrderID == ord.OrderID).FirstOrDefault(); 
            .  .  . 
 
            return Json(myObject.Value); 
 
        } 
        public ActionResult Insert(CRUDModel myObject) 
        { 
            var ord = myObject.Value; 
            orddata.Insert(0, ord); 
            return Json(myObject.Value); 
        } 
        public ActionResult Remove(CRUDModel myObject) 
        { 
            orddata.Remove(orddata.Where(or => or.OrderID == myObject.key).FirstOrDefault()); 
            return Json(new { result = orddata, count = orddata.Count }); 
        } 
 
       
        public class TestDm : DataManagerRequest 
        { 
            public string ej2Grid { get; set; } 
        } 
 
        public class CRUDModel 
        { 
            public List<OrdersDetails> Added { get; set; } 
            public List<OrdersDetails> Changed { get; set; } 
            public List<OrdersDetails> Deleted { get; set; } 
            public OrdersDetails Value { get; set; } 
            public int key { get; set; } 
            public string action { get; set; } 
            public string ej2Grid { get; set; } 
        } 
} 
 
 
 
 
Please get back to us for further assistance. 
 
Regards, 
Pavithra S. 


Loader.
Live Chat Icon For mobile
Up arrow icon