[RESOLVED]How to pass records between Views?

I have a table of records and a submit button.
How do i Pass those records from one view to another another view while clicking the Submit Button?

Thanks in advance!

From the view, the data goes to the respective controller. That’s the route. From that controller you can server your desired view and pass the data to it as model object.

Using the following in the controller action method:

return View("AnotherView",ModelObject);

How did your table initially populate with records?  Action and View code would be useful

Do you mean view to view or from one controller to another controller? What I get from the question is that on submit you will be calling another page/controller?

If it is controller to another controller then use tempdata. 

How to pass data in ASP.Net MVC app refer below

http://msdn.microsoft.com/en-in/library/dd394711(v=vs.100).aspx

there is no direct passing of data between views. a view is html that is returned to the browser. when that view contains an anchor (link) to request a new html page, data can be passed via the query string. if its a form submit, then the form fields are
passed. MVC’s data binder will bind these field to the action parameters (often a model).

so to pass data from one form to another usually requires a form, and submit. all data must be in a <input>, <select> or <textarea>. to pass a complete object, each property must be written to a form field, or that property will not be in the postback data
(which is a name/value collection).

if you are writing a javascript application, then there are more ways to pass data via ajax or dynamic forms, but thats different

You cannot pass data directly from view to another view on submit

you submit data to action and action returns the view by passing the data

Can you give me any sample code on how to pass list of records from one table to another table?

from html table to html table?

or

db table to db table?

From HTML table to another HTML table

check this

<table id="table1" border="1">
    <tr> <td>ID</td> <td>Name</td></tr>
    <tr> <td>1</td><td>Name1</td> <td><input type="checkbox" id="movebutton" value="Move" onclick="MoveRow(this)" /></td> </tr>
    <tr> <td>2</td><td>Name2</td> <td><input type="checkbox" id="movebutton" value="Move" onclick="MoveRow(this)" /></td> </tr>
    <tr> <td>3</td><td>Name3</td> <td><input type="checkbox" id="movebutton" value="Move" onclick="MoveRow(this)" /></td> </tr>
    <tr> <td>4</td><td>Name4</td> <td><input type="checkbox" id="movebutton" value="Move" onclick="MoveRow(this)" /></td> </tr>
</table>
<br />
<br />
<br />
<table id="table2" border="1"><tr> <td>1</td><td>Name1</td> <td></td></table>

    <script>
        function MoveRow(movebutton) {
            var table2 = document.getElementById("table1");
            var table2 = document.getElementById("table2");
            var rowchecked = movebutton.parentNode.parentNode;
            var rowcheckedClone = rowchecked.cloneNode(true);
            var checked = movebutton.checked;
            var foundIndex = -1;
            rowcheckedClone.deleteCell(0);
            rowcheckedClone.deleteCell(1);

            for (var i = 0; i < table2.rows.length; i++) {
                if (rowcheckedClone.isEqualNode(table2.rows[i])) {
                    foundIndex = i;
                }
            }
            if (checked) {
                if (foundIndex == -1)
                    table2.appendChild(rowcheckedClone);
            }
            else {
                if (foundIndex > -1)
                    table2.deleteRow(foundIndex);
            }
        }
    </script>

Leave a Reply