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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to get selected rows from Grid EJS

Thread ID:

Created:

Updated:

Platform:

Replies:

150989 Jan 27,2020 01:11 PM UTC Jan 29,2020 11:47 AM UTC ASP.NET MVC - EJ 2 1
loading
Tags: Grid
Bart
Asked On January 27, 2020 01:11 PM UTC

Hi, I have a problem, because in my opinion this code should be work correctly but.. it doesn't and I don't know where is problem. 

I want to get selected rows from grid and pass them to hiddenFor string property (to HttpPost method in my Controller) 

When I call the post method, inside my ViewModel a hiddenFor property is " [] " (empty?)

My code of view and controller is in attachement.

P.S: Curiosity - the same code works fine in another part of my application.... so I am really frustrated

Thanks for help.
Regards.


Attachment: view_controller_780bd4c7.zip

Prasanna Kumar Viswanathan [Syncfusion]
Replied On January 29, 2020 11:47 AM UTC

Hi Bart, 
 
Greetings from syncfusion support 
 
From analyzing your query we understand you want to send the grid selected records to the server by using hiddenFor string property. But in your code example we did not found any code related to the getting the selected records. So Please share the code example of getting selected rows from grid. 
 
Based on your requirement you need to send the selected records to the server side. To achieve this requirement we suggest you to use ajax post in your code example. Please find the below code example. 
 
 
<script> 
    document.getElementById('button').onclick = function () { 
        var grid = document.getElementsByClassName('e-grid')[0].ej2_instances[0]; 
        var selectedRecords = grid.getSelectedRecords(); 
        var rows = JSON.stringify(selectedRecords); 
        var ajaxObj = new ej.base.Ajax(); 
        ajaxObj.type = 'POST'; 
        ajaxObj.contentType = 'application/json'; 
        ajaxObj.url = '/Home/SelectRecord'; 
        ajaxObj.data = rows; 
        ajaxObj.beforeSend = function (xhr) { 
            xhr.httpRequest.setRequestHeader("XSRF-TOKEN", 
 
                $('input:hidden[name="__RequestVerificationToken"]').val()); 
 
        }; 
        ajaxObj.send().then(function (value) { 
            //you can use the below way to convert the date 
            var parsed = ej.data.DataUtil.parse.parseJson(value); 
            console.log(parsed); 
        }); 
    }; 
</script> 
 
If we misunderstood your query please get back us with your exact requirement. 
 
Regards, 
Prasanna Kumar N.S.V 


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.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

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

Live Chat Icon For mobile
Live Chat Icon