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.
Unfortunately, activation email could not send to your email. Please try again.

MVC Grid odata datasource not passing the entity on PUT.

Thread ID:

Created:

Updated:

Platform:

Replies:

117354 Oct 2,2014 10:18 PM Oct 3,2014 06:43 AM ASP.NET MVC 1
loading
Tags: Grid
James
Asked On October 2, 2014 10:18 PM

I am having trouble with editing a row in a Grid control. I am using web api odata controllers. I was able to successfully load and display the grid with data from the datasource but when I try to update a row and save the correct method for the controller is called but the "Delta patch" attribute is always null. "public IHttpActionResult Put([FromODataUri] int key, Delta patch)"

The key passed is correct. What am i missing to be able to update?        

also the summary row does not calculate a value.


Here is my grid:

        @(Html.EJ().Grid("AccountSummaryGrid")
              .Datasource(ds => ds.URL("/odata/Funds").CrossDomain(true))
              .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);
              }))
              .EnablePersistence(false)
              .AllowSorting()
              .SummaryRow(row =>
              {
                  row.Title("Total").SummaryColumns(col => { col.SummaryType(SummaryType.Sum).Format("{0:C}").DisplayColumn("Total").DataMember("Total").Add(); }).Add();
              })            
              .Columns(col =>
              {
                  col.Field("Id").Visible(false).IsPrimaryKey(true).IsIdentity(true).Add();
                  col.Field("Name").HeaderText("Fund Name").Width(75).EditType(EditingType.String).ValidationRules(v => v.AddRule("required", true)).Add();
                  col.Field("PeriodicAmount").HeaderText("Deposit Amount").TextAlign(TextAlign.Right).Width(80).EditType(EditingType.Numeric).Format("{0:C}").NumericEditOptions(new EditorProperties() { DecimalPlaces = 2 }).Add();
                  col.Field("Total").AllowEditing(false).Format("{0:C}").HeaderText("Total").Width(80).TextAlign(TextAlign.Right).Add();
              }))

Mohammed Farook J [Syncfusion]
Replied On October 3, 2014 06:43 AM

Hi James,

 

Thanks for using Syncfusion products,

 

Query 1:

 

 I am having trouble with editing a row in a Grid control. I am using web api odata controllers. I was able to successfully load and display the grid with data from the datasource but when I try to update a row and save the correct method for the controller is called but the "Delta patch" attribute is always null. "public IHttpActionResult Put([FromODataUri] int key, Delta patch)"

The key passed is correct. What am i missing to be able to update?   

 

     We have analyzed your provided code , we glad to achieve your requirement by using “customAdaptor  with Grid load events”. We have created a sample as ”Web api controller with edit options  enabled in EjMVCGrid”.

 

The Custom adaptor is for Grid datasource to pass values to Web Api controller for Edit operation. Please refer the following code snippets.

 

 

[cshtml]

 

<script src="~/Scripts/ej/CustomAdaptor.js">script> @*refer customAdaptor*@

 

@(Html.EJ().Grid<object>("Grid")

.Datasource(ds => ds.URL("Api/Orders"))

.EditSettings(e=> e.AllowEditing().AllowDeleting().AllowAdding())

.ClientSideEvents(e => e.Load("load"))

.AllowPaging()

.Columns(col =>

        {

           . . .       

        }))

<script type="text/javascript">

    function load() {

        this.model.dataSource.adaptor = new adaptor1();//grid loads with customAdaptor

    }

script>

 

[web api]

 

public class OrdersController : ApiController

    {

        // GET api/

        NORTHWNDEntities1 db = new NORTHWNDEntities1();

      

        public PageResult<Order> Get(ODataQueryOptions opts)

        {

             var results = opts.ApplyTo(db.Orders.AsQueryable());

            var data = db.Orders.AsQueryable();

            return new PageResult<Order>((IEnumerable<Order>)results, Request.GetNextPageLink(), data.Count());

        }

 

        // Edit api//

        public void Put(Order value)

        {

             db.Entry(value).State = EntityState.Modified;

             db.SaveChanges();

        }

 

    }

}

 

 

For your convenience we have attached a sample and the same can be downloaded from the link:

 

Sample Location:    Sampl124550.zip

 

Query 2:

also the summary row does not calculate a value

 

 Sorry about the inconvenience caused.

 

Currently we do not have  support for Summary Calculation in  OData request.

 

Please let us know if you have any queries,

 

Regards,

J.Mohammed Farook


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.

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.

;