Я создаю одну страницу отчета для всех отчетов на основе @RouteData.Values
.Все мои отчеты поступают с HomeController
, и я просто хочу отобразить их на #table1
на странице Razor.
Отчеты имеют динамический размер в строке и столбце.
Отчеты RazorPageView
@page "{id}"
@model Test.Pages.Reports.IndexModel
<table id="table1" class="table table-responsive">
</table>
@section Scripts {
<script type="text/javascript">
$(document).ready(function () {
var id = @RouteData.Values["id"];
switch (id) {
case 'Customers':
apipath = 'GetAllCustomers';
break;
case 'Vendors':
apipath = 'GetAllVendors';
break;
default:
apipath = 'SomeOtherReport';
}
$.ajax({
url: "/Home/" + apipath,
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: JSON,
success: function (result) {
//Here i want to load dynamic type table data to #table1
}
});
});
</script>
}
Домашний контроллер
public class HomeController : Controller
{
[HttpGet]
public ActionResult GetAllCustomers()
{
var result = _Context.Customers.ToList();
return Json(result);
}
[HttpGet]
public ActionResult GetAllVendors()
{
var result = _Context.Vendors.ToList();
return Json(result);
}
}
, чтобы мой URL выглядел "~ / Отчеты / Клиенты" или "~ / Отчеты / Продавцы"