htmlmodel-view-controllerhtml-tablecontrollerformcollection

get html table in asp.net mvc controller without ajax call


I am creating a web in in which I have a table,

<table>
   @foreach (var test in Model.testingdata)
   {
       <tr>
            <td>
                 <input type="hidden" name="testSpan @i" value="@test.ID" />
            </td>
       </tr>
   }
</table>

I want to get the data of this table in my mvc controller without any ajax call

what is a way of getting the data in my controller


Solution

  • I misunderstood in the comments, I thought you were trying to render data rather than post it back to the server.

    To do this without javascript or ajax you could post the data as a form.

    For this you should wrap your table in a form element. For example

    <form action="/post-location" method="post">
      <table> .... </table>
      <input type="submit" value="Submit">
    </form>
    

    When you click the submit button it will post the data to the location specified in the 'action' field.

    See this example: https://www.w3schools.com/tags/tag_form.asp