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

Returning the select grid row to controller's post method

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 

1 Reply

ES Eswari S Syncfusion Team August 6, 2013 04:30 AM UTC

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


Loader.
Live Chat Icon For mobile
Up arrow icon