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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

CRUD POST and entity framework

Thread ID:

Created:

Updated:

Platform:

Replies:

143219 Mar 10,2019 04:35 AM UTC Mar 11,2019 08:40 AM UTC ASP.NET MVC - EJ 2 1
loading
Tags: Grid
José Manuel
Asked On March 10, 2019 04:35 AM UTC

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

Pavithra Subramaniyam [Syncfusion]
Replied On 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. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;