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.
Syncfusion Feedback

Returning the selected row in a grid

Thread ID:

Created:

Updated:

Platform:

Replies:

118424 Mar 6,2015 11:37 PM UTC Jun 2,2016 06:59 AM UTC ASP.NET MVC 3
loading
Tags: Grid
Doug Matulis
Asked On March 6, 2015 11:37 PM UTC

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

Madhu Sudhanan P [Syncfusion]
Replied On 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



Ashok Bhupathy
Replied On June 1, 2016 04:05 AM UTC

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

Ragavee U S [Syncfusion]
Replied On 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. 


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

;