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.

Returning the select grid row to controller's post method

Thread ID:

Created:

Updated:

Platform:

Replies:

110420 Aug 1,2013 03:53 PM Aug 6,2013 12:30 AM ASP.NET MVC (Classic) 1
loading
Tags: Grid
Doug Matulis
Asked On August 1, 2013 03:53 PM

Hello, I am using the Grid controls in a ASP.NET MVC 4 application and can figure out how to get the selected row from each grid in my post method on my controller class.  Any help us greatly appreciated.

I have tried using the .ClientSideEvents property for the grid as follows but it does nothing:
.
.
.ClientSideEvents(r => r.OnRecordSelectionEvent("ContractorRecordSelection"))
.
.

<script type="text/javascript"> 

    function ContractorRecordSelection(sender, args) {
        var selectedRows = sender.selectedRows();
        var a = args.record.Code;
        $("#SelContractorID").val(args.record.ID)
        $("#SelContractorName").val(args.record.Name)
        $("#SelContractorCity").val(args.record.City)
}
</script>

Thanks,
Doug 

Eswari S [Syncfusion]
Replied On August 6, 2013 12:30 AM

Hi Doug,

Thank you for using Syncfusion products.

Your requirement can be achieved in “OnRecordSelectionEvent”. Please refer to the following steps in the sample:          

 

Step #1: Add client side event for RecordSelection.

[Aspx]

@{ 

    Html.Syncfusion().Grid<Grid_CS_Razor.Models. Student >('GenericListGrid')

                    . . . .

    .ClientSideEvents(eve => {

        eve.OnRecordSelectionEvent('recordSelect');  // record selection event

    })

    }

Step#2:

[JavaScript]

function recordSelect(sender, args)

    var record = Sys.Serialization.JavaScriptSerializer.serialize(args.record);   // can get selected record values in args.record

    $.ajax({

        type: 'Post',

        url: 'Home/GetRecords',

                 data: { rec: record },  // send serialized data to controller through ajax post

        dataType: 'html',

        success: function (data) {

            return data;

        }

    });

}

Step #3:

[Controller]

[AcceptVerbs(HttpVerbs.Post)]

        public ActionResult GetRecords(string rec)  // retrieve the data here and desterilize it

        {

            Student ord = new JavaScriptSerializer().Deserialize<Student >((string)rec);  // can get selected record values here

            return RedirectToAction('Index');

        }

For your convenience ,we have prepared the sample and the same can be downloaded from the following link:

Sample.zip

 

Please try this and let us know if you have any queries.

 

Regards,

Eswari 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.

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.

;