0
 <table id="example1" class="table table-bordered table-striped">
                        <thead>
                            <tr>
                                @*<th style="width:0px"></th>*@
                                <th>Name</th>
                                <th>Quantity</th>
                                <th>Unit Price</th>
                                <th>Total Price</th>
                                <th>Company Name</th>
                                <th style="display:none"></th>

                                <th></th>
                            </tr>
                        </thead>
                        <tbody>

                           @foreach (var item in list)
                        {

                                <tr>

                                    <td name="pname">@item.Material_Name</td>
                                    <td name="pprice">@item.Quantity</td>
                                    <td name="pdetail">@item.Unit_Price</td>
                                    <td name="pdetail">@item.Total_Price</td>
                                    <td name="pdetail">@item.Name</td>
                                    <td name="pid" style="display:none; white-space:nowrap">item.Id</td>

                                </tr>
                           }

                        </tbody>
                    </table>
                    <button class="btn btn-primary btn-lg btn-block" name="save" type="button">Print</button>

I want to get list of products from datatable at action.after getting the list i want to print that list. Now i just want to get list from datatable to action.

1 Answers1

1

You need to use BeginForm

Then on click of submit button, you can see your data in to Post Action method.

  @model IList<PaymentSchedule>

  @using (Html.BeginForm("SubmitDataToUpload", "Payment", FormMethod.Post, new {enctype = "multipart/form-data"}))
  {

              <table id="example1" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            @*<th style="width:0px"></th>*@
                            <th>Name</th>
                            <th>Quantity</th>
                            <th>Unit Price</th>
                            <th>Total Price</th>
                            <th>Company Name</th>
                            <th style="display:none"></th>

                            <th></th>
                        </tr>
                    </thead>
                    <tbody>

                       /*@foreach (var item in list)*/
        /* foreach loop does not generate the correct name attributes */
                   for(int i = 0; i < Model.Count; i++)
                    {

                            <tr>
                           <td>@Html.TextBoxFor(m =>Model[i].Material_Name)</td>
                           <td>@Html.TextBoxFor(m =>Model[i].Quantity)</td>
                           <td>@Html.TextBoxFor(m =>Model[i].Unit_Price)</td>
                           <td>@Html.TextBoxFor(m =>Model[i].Price)</td>
                           <td>@Html.TextBoxFor(m =>Model[i].Company)</td>
                           <td>@Html.TextBoxFor(m =>Model[i].Id)</td>         

                            </tr>
                       }

                    </tbody>
                </table>



              /*Update : Added Submit Button*/

              <input class="btn btn-success" type="submit" value="Submit"/>
               

       }


     public ActionResult SubmitDataToUpload(List<PaymentSchedule> paymentSchedules)
     {
        //Add to paymentSchedule
        return View("ViewName",paymentSchedules);
     }

foreach loop does not generate the correct name attributes for more info : Review This Link

Community
  • 1
  • 1
Saurin
  • 1,650
  • 1
  • 10
  • 8
  • 1
    You have not form controls so nothing is submitted (and a `type="button"` does not submit a form anyway) –  Jan 31 '18 at 05:19
  • Update the ans, Thank you for correcting – Saurin Jan 31 '18 at 05:26
  • You still have not form controls in the form so nothing at all is submitted to the server –  Jan 31 '18 at 05:26
  • I am obliged, thank you for pointing out, eventually got a new thing to learn today! – Saurin Jan 31 '18 at 05:34
  • That still does not work - you cannot use a `foreach` loop - refer [Post an HTML Table to ADO.NET DataTable](https://stackoverflow.com/questions/30094047/post-an-html-table-to-ado-net-datatable/30094943#30094943) to understand why –  Jan 31 '18 at 05:36
  • Sir i want list. – Sohail Asghar Jan 31 '18 at 05:42
  • Stephen Muecke, I am in shame, did such a worst ans in post earlier without rethinking, @SohailAsghar, try last updated code, and let me know if any issue. – Saurin Jan 31 '18 at 06:09
  • Well the answer now works, but the real issue is the question - why on earth would OP want to send back exactly the same data to the controller that the controller just sent to the view (OP was not originally editing anything) so its all a bit pointless ) –  Jan 31 '18 at 06:25
  • i want to print in pdf form after making some changes from view – Sohail Asghar Jan 31 '18 at 06:37
  • still not working – Sohail Asghar Jan 31 '18 at 06:37
  • @SohailAsghar, What problem you faced now ? it should work as I have tested it locally, – Saurin Jan 31 '18 at 07:46