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
close icon

Returning the selected row in a grid

Hello,

I have a grid that is in a form with other controls.  When the submit button is pressed and control returns
to the Post method in the controller, how do I pass back the selected row in the grid to the controller method?

Thanks,
Doug

3 Replies

MS Madhu Sudhanan P Syncfusion Team March 9, 2015 01:06 PM UTC

Hi Doug,

Thanks for using Syncfusion products.

We can achieve your requirement with the following steps. Please refer them.

1. Place a hidden type input element in the form as follows.

    

@using (Html.BeginForm())

    {

      

        <input type="hidden" name="GridData" id="GridData" value=""/>

        . . . .

      

        <input type="submit" value="Submit" />

    }

    

2. Retrieve the selected row of grid using RowSelected event and update it in the hidden element.

@using (Html.BeginForm())

    {

      

        <input type="hidden" id="GridData" value=""/>

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

.Datasource((IEnumerable<object>)ViewBag.datasource)

.AllowPaging()

    . . . . . .

        .ClientSideEvents(evt => evt.RowSelected("onRowSelected")))

        <input type="submit" value="Submit" />

    }

[JS]

function onRowSelected(args) {

        //Retrieve the selected recrods of the grid

        var result = this.getSelectedRecords();

        //stringify and place the grid`s selected record as value of hidden element

        $("#GridData").val(JSON.stringify(result));

    }

3. Now on form submit, we can retrieve the selected row data at the controller side using the name “GridData”.

     

Please let us know if you need further assistance.

Regards,

Madhu Sudhanan. P




AB Ashok Bhupathy June 1, 2016 04:05 AM UTC

Hi am getting null for "GridData" when post the form data, could you please resolve this issue.


RU Ragavee U S Syncfusion Team June 2, 2016 06:59 AM UTC

Hi Ashok, 

We are able to reproduce the issue if the name attribute for the hidden element is not specified. So please ensure if you have specified the “name” attribute for the hidden element. 

For your reference, we have created a sample which can be downloaded from the below location. 


Regards, 
Ragavee U S. 


Loader.
Live Chat Icon For mobile
Up arrow icon