locked
How can I pass the value from datatable column id into the controller method RRS feed

  • Question

  • User-1355965324 posted

    Hi

    Please can you help me how to pass the valued  in data into the controller  method argument   

     <table id="tblDepotMeter" class="table table-striped table-bordered" style="width:100%">
                                    <thead>
                                        <tr>
                                            <th>MeterCode</th>
                                            <th>Description</th>
                                            <th></th>
    
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <tr>
                                            <td>MeterCode</td>
                                            <td>Description</td>
                                            <td>MeterID</td>
    
                                        </tr>
                                    </tbody>
                                </table>
    <script>
    dataTable = $('#tblDepotMeter').DataTable({
                "ajax": {
                     "url": "/DepotAssets/GetDepotMeterList?depotno=" + depotno,
                    "type": "GET",
                    "datatype": "json",
                    "dataSrc": function (json) {
                        return JSON.parse(json);
                    }
                },
    "columns": [
                    { "data": "MeterCode", "width": "50%" },
                    { "data": "Description", "width": "20%" },
                    { "data": "MeterID",
                        "render": function (data) {
                            
                        return `<div class="text-center">
                                    <a href="/DepotAssets/UpdateMeter/${data}" class='btn btn-success text-white' style='cursor:pointer; width:100px;'>
                                        <i class='far fa-edit'></i> Edit
                                    </a>
    </script>
    
     public IActionResult UpdateMeter(int? id)  //  id not passing here please help
            {
                 
                return View();
    
            }
    
    
    
    
    

    Sunday, December 1, 2019 9:15 PM

Answers

  • User-1355965324 posted

    I corrected the code as given below , it is working fine .

    Thanks 

     <a href="/DepotAssets/UpdateMeter?id=${data}" class='btn btn-success text-white' style='cursor:pointer; width:100px;'>
                                        <i class='far fa-edit'></i> Edit
                                    </a>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 2, 2019 6:19 AM

All replies

  • User-474980206 posted

    What isn’t working? Using the browser debug tools, what is the render html for the column? Are you using a browser that supports template strings?

    Monday, December 2, 2019 1:19 AM
  • User-1355965324 posted

    The value from ${data} is not passed  in to the controller .   The method is  being called but the argument int? id is null in the UpdateMeter().

    When I debug  in browser,  the method is called as DepotAssets/UpdateMete/100. 

    100 is  id number but it is not being passed as argument into the method

    Thanks

    Pol

    Monday, December 2, 2019 5:48 AM
  • User-1355965324 posted

    I corrected the code as given below , it is working fine .

    Thanks 

     <a href="/DepotAssets/UpdateMeter?id=${data}" class='btn btn-success text-white' style='cursor:pointer; width:100px;'>
                                        <i class='far fa-edit'></i> Edit
                                    </a>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 2, 2019 6:19 AM