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 using UrlAdaptor Passing Data To Controller

Thread ID:

Created:

Updated:

Platform:

Replies:

131878 Aug 1,2017 01:21 PM UTC Aug 3,2017 12:33 PM UTC ASP.NET Core 3
loading
Tags: Grid
Steven Olensky
Asked On August 1, 2017 01:21 PM UTC

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>

Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On 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. 


Steven Olensky
Replied On 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>


Seeni Sakthi Kumar Seeni Raj [Syncfusion]
Replied On 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. 


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.

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

;