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

How to get selected rows from Grid EJS

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

1 Reply

PK Prasanna Kumar Viswanathan Syncfusion Team 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 


Loader.
Live Chat Icon For mobile
Up arrow icon