Click here to Skip to main content
15,936,887 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created JQuery Datatable to populate just one column containing multiple records.
I want doing that, i select the column cell value and any keydown have pressed (i.e. key value is = 69) that cell, the selected record to passing i.e. id value from razor view to controller.
But Passing id parameter value is not showing into controller.
It is shown null value....
Why it is????
I want to solution in favour of my above code of that problem....
Please help me any body.

What I have tried:

$(document).ready(function () {
url: 'Unit/GetUnit',
method: 'post',
dataType: 'json',
success: function (data) {
select: {
//style: 'single'
keys: true,
data: data,
paging: false,
searching: false,
ordering: false,

scrollY: 200,
columns: [
data: 'UnitID',
width: '10px'
data: 'Name',
width: '300px',
//searchable: false,
columnDefs: [
{ className: 'dt-body-center', targets: [0] },//"UnitID"
{ visible: false, targets: [0] },
{ className: 'dt-body-left', targets: [1] }//"Name"

function KeyEventHandler() {
$('#datatable').on('key', function (e, datatable, key, cell, originalEvent) {
if (key == 69) {
var tbl = $('#datatable').DataTable();
var pID = tbl.row('tr').data()['UnitID'];

window.location.href = "Unit/Edit?UnitID" + pID + "";
Updated 7-Oct-19 7:22am
Richard Deeming 7-Oct-19 13:34pm    
DO NOT edit my solution to add your controller code! It's irrelevant to the question.

1 solution

You seem to be missing an = in your querystring:
window.location.href = "Unit/Edit?UnitID=" + encodeURIComponent(pID);
Share this answer
Member 7678194 8-Oct-19 9:55am    
not working as per your instruction.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900