I have spent hours searching all over the internet but it seems no one has a current answer. I have a simple table set up in a PARTIAL view and want to export the data in the html table not from the database. I do not have the option of using any plugins either. I am open to doing it through JavaScript/Jquery but I am fairly new to MVC and I have exhausted other solutions on the internet.
Address Book Summary (Partial View):
<table class="table table-bordered table-responsive table-striped" id="tblAddressBook">
<thead>
<tr>
<th> @Html.DisplayNameFor(model => model.Name)</th>
<th> @Html.DisplayNameFor(model => model.Address)</th>
<tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<td class="text-right">@Html.DisplayFor(modelItem => item.Name)</td>
<td class="text-right">@Html.DisplayFor(modelItem => item.Address)</td>
}
</tbody>
<tfoot>
<td class="text-right>Model.Sum(model => model.TotalPeople))</td>
<td class="text-right>Model.Sum(model => model.Addresses))</td>
</tfoot>
Address Book
<button type="button" class="btn btn-primary">
Export
</button>
<div id="summaryAddressBook">
@Html.Partial("AddressBook/_Summary", Model.Peoples)
</div>
Address Book Controller
public ActionResult Export() {
Response.ContentType = "application/x-msexcel";
Response.AddHeader("Content-Disposition", "attachment;filename=ExcelFile.xls");
return View();
}