0

i am new to mvc so please help

please see the fiddle https://jsfiddle.net/shaswatatripathy/9d0oknyt/2/

here i have a table and I have to write a jquery function which will get all the rows which have status as modified and send data to controller action and access this data to create datatable in controller action

the table is dynamic -many rows can come up there so need a jquery function which will be invoked on a button click and get rows details with status modified

html

    <table id="mytable">
<thead>
  <tr>
    <th>Name</th>
    <th>Address</th>
    <th>Gender</th>
    <th>status</th>
  </tr>
</thead>
<tbody>
  <tr>
    <td>jhon</td>
    <td>us</td>
    <td>male</td>
    <td>static</td>
  </tr>
   <tr>
    <td>joana</td>
    <td>washington</td>
    <td>female</td>
    <td>static</td>
  </tr>
   <tr>
    <td>steve</td>
    <td>belgium</td>
    <td>male</td>
    <td>modified</td>
  </tr>
   <tr>
    <td>jimmy</td>
    <td>angola</td>
    <td>male</td>
    <td>modified</td>
  </tr>
    <tr>
    <td>lisa</td>
    <td>india</td>
    <td>female</td>
    <td>modified</td>
  </tr>
</tbody>
</table>

<br />
<input type="button" onclick="sendDetailsToControllerAction()" value="get details"/>

css

table {
    border-collapse: collapse;
}

table, th, td {
    border: 1px solid black;
}
  1. i can use jquery ajax method to send data to my controller action

server side

public actionResult GetDetails()
{


    return view();
}

how to get details of every row with status modified and send it controller .

table header names and column names in my data table which i will create in action will be different .

i dont need that much help creating datatable out of data , but dont know how to send that data and get it

1 Answer 1

1

Using below function you will be able to get "modified" rows and save those row in array and then you can use $.ajax to call your Action in controller

<script type="text/javascript">

        function sendDetailsToControllerAction() {
            var tableData = document.getElementById('mytable');
            var numberOfRows = tableData.rows.length;
            for (var i = 1; i < numberOfRows; i += 1) {
                var row = tableData.rows[i];
                if (row.cells[3].innerText == 'modified') {
                   //Rows which have modified status
                    console.log(row)
                }
            }
        }

    </script>
Sign up to request clarification or add additional context in comments.

2 Comments

I Can not get rows as this table is from a partial view so , its every time its rows is 0 . can you put some jquery code
like find the table and put it in json and deserailize in controller action

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.