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

CRUD using UrlAdaptor Passing Data To Controller

I'm a little confused. I can't seem to find the correct syntax for passing data to the controller when using UPDATE, INSERT, and REMOVE.

For example, I have a method in the Controller for UPDATE. How do I get the data from the grid row to update?

        public ActionResult PerformUpdate(object value)  // What goes here ?????
        {
            dbContextPsMisc db = new dbContextPsMisc();
            cvLog table = db.cvLogs.Single(o => o.Id == param.value.Id);
            db.Entry(table).CurrentValues.SetValues(param.value);
            db.Entry(table).State = EntityState.Modified;
            db.SaveChanges();
            return RedirectToAction("GetLogData");
        }

Razor...

<ej-grid id="Grid" allow-paging="true" allow-sorting="true" allow- allow-resize-to-fit="true"  allow-searching="true">
    <e-datamanager url="GetLogData" update-url="PerformUpdate" insert-url="Insert" remove-url="Delete" adaptor="UrlAdaptor"></e-datamanager>
    <e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" edit-mode="Dialog"></e-edit-settings>
    <e-toolbar-settings show-toolbar="true" toolbar-items='@new List<string> {"add","edit","delete","update","cancel","search"}' />
    <e-columns>
        <e-column field="id" is-primary-key="true" header-text="Id" visible="false"></e-column>
        <e-column field="dateCreated" header-text="Date Created" format="{0:MM/dd/yyyy}"  text-align="Left" width="120"></e-column>
        <e-column field="actions" text-align="Left"></e-column>
    </e-columns>
</ej-grid>

3 Replies

SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 2, 2017 12:56 PM UTC

Hi Steven,  
 
Thanks for contacting Syncfusion Support.  
 
We have to use a FromBody attribute along with the CRUDModel class and defined Model class of the Receiving object. So, the objects will be deserailzed which is easy for us to handle. Refer to the following code example and Help Document. 
 
        public ActionResult PerformUpdate([FromBody]CRUDModel<Orders> value) 
        { 
              . . . 
                . . . 
        } 
 
    public class Orders { 
        public int id { get; set; } 
        public DateTime dateCreate { get; set; } 
        public string actions { get; set; } 
    } 
 
 
Regards,  
Seeni Sakthi Kumar S. 



SO Steven Olensky August 2, 2017 06:40 PM UTC

Ok, I got the Update to work, however on INSERT the param value is always null.

   public ActionResult PerformUpdate([FromBody]CRUDModel<cvLog> param)

        {

            dbContextPsMisc db = new dbContextPsMisc();

            var rec = param.Value;

            var val = db.cvLogs.Where(x => x.Id == rec.Id).FirstOrDefault();

            //lookup original record and only change input fields

            val.Actions = rec.Actions;

            val.DateCreated = rec.DateCreated;

            db.SaveChanges();

            return Json(param.Value);

        }


        public ActionResult Insert([FromBody]CRUDModel<cvLog> param)

        {

            param.Value.Id = Guid.NewGuid();

            using (var db = new dbContextPsMisc())

            {

                db.Add(param.Value);

            }

            return Json(param.Value);

        }


<ej-grid id="Grid" allow-paging="true" allow-sorting="true" allow- allow-resize-to-fit="true" allow-searching="true" action-complete="complete">

    <e-datamanager json="Model" update-url="PerformUpdate" insert-url="Insert" remove-url="DeleteUrl" adaptor="remoteSaveAdaptor"></e-datamanager>

    <e-edit-settings allow-adding="true" allow-editing="true" allow-deleting="true" edit-mode="InlineFormTemplate" 

                     inline-form-template-id="#template" ></e-edit-settings>

    <e-toolbar-settings show-toolbar="true" toolbar-items='@new List<string> {"add","edit","delete","update","cancel","search"}' />

    <e-columns>

        <e-column field="Id" is-primary-key="true" header-text="Id" visible="false"></e-column>

        <e-column field="DateCreated" header-text="Date Created" format="{0:MM/dd/yyyy}" text-align="Left" width="120"></e-column>

        <e-column field="Actions" text-align="Left"></e-column>

        <e-column field="AccountId" visible="false"></e-column>

    </e-columns>

</ej-grid>


@section Scripts {


    <script id="template" type="text/template">

        <input type="hidden" id="Id" name="Id" value="{{: Id}}" />

        <table cellspacing="10">

            <tr>

                <td>Date Created</td>

                <td style="text-align: left">

                    <input id="DateCreated" name="DateCreated" value="{{: DateCreated}}" class="form-control" style="width:116px;height:28px" />

                </td>


                <td>Action</td>

                <td style="text-align: left; width: 300px">

                    <input id="Actions" name="Actions" value="{{: Actions}}" class="form-control"

                           style="width: 300px; height: 28px" />

                </td>

            </tr>

        </table>

    </script>


    <script>

        function complete(args) {

            $("#DateCreated").ejDatePicker({ dateFormat: "MM/dd/yyyy" });

        }


    </script>



SS Seeni Sakthi Kumar Seeni Raj Syncfusion Team August 3, 2017 12:33 PM UTC

Hi Steven,  
 
We are unable to reproduce any problem at our end. We have prepared a sample that can be downloaded from the following location.  
 
 
However, we have noticed that you are updating the Primary key alone in the server alone and hiding it in the client-end. For handling these cases, Grid provides an is-identity property of the Grid e-columns. Please refer to the following   
 
<ej-grid id="FlatGrid" allow-paging="true">  
        <e-columns> 
            <e-column field="OrderID" is-identity="true" is-primary-key="true" visible="false" text-align="Right" width="75"></e-column> 
                . . . 
        </e-columns> 
    </ej-grid> 

 
 
If you are still facing any problem, please share the following information to analyze the problem at our end.  
 
  1. Screenshot with the replication procedure or Video demo of the application
  2. Version of the Essential Studio
  3. If possible, modify the attached sample and reproduce
 
Regards,  
Seeni Sakthi Kumar S. 


Loader.
Live Chat Icon For mobile
Up arrow icon