I want to create table rows when dropdown value is selected, but at the moment it just returns nothing. I tried changing data.notices to just data, but then it returns "undefined".
View:
<script>
$(document).ready(function () {
$('select').formSelect();
});
function onManagerChange() {
var id = $("#Managers").val();
var rows = "";
$.ajax({
type: "GET",
url: "@Url.Action("GetFilteredReports", "FinalReports")",
dataType: "application/json",
data: { "id": id },
success: function (data) {
$("#Reports").html("");
$.each(data.notices, function (id, report) {
rows += `
<tr> +
<td> + ${report.ReportName} + </td> +
<td> + ${report.ReportState} + </td> +
<td> + <a class="btn-small waves-effect waves-light" asp-action="Download" asp-route-id="report.ID">Download</a> + </td> +
</tr>`
});
$("#Reports").html(rows);
}
});
}
Controller:
public IActionResult GetFilteredReports(int id)
{
var reportsList = _context.Reports.Include(x => x.ReportManager).Where(x => x.ReportManager.ID == id).ToList();
return Json(reportsList);
}
type: "GET",You need to send the id to theGetFilteredReports(int id), so this istype: "Post",FinalReportsactually returns. Then add a javacsript breakpoint and step through your code