My controller doesn't come back to list after deleting an item from the list, in browser it throws this error
This localhost page can’t be found. No web page was found for the web address: https://localhost:44384/RaidRequests/IndexAsync
This started then I added my pagination, i took care of all other problems with my views, but delete just doesn't work.
this is my delete function in my controller:
public async Task<IActionResult> DeleteConfirmed(int? id)
{
var raidRequest = await _context.RaidRequest.FindAsync(id);
_context.RaidRequest.Remove(raidRequest);
await _context.SaveChangesAsync();
return RedirectToAction(nameof(IndexAsync));
}
and my index looks like this:
public async Task<ViewResult> IndexAsync(string sortOrder, string currentFilter, string searchString, int? page)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.NameSurnameSortParm = sortOrder == "NameSurname" ? "NameSurname_desc" : "NameSurname";
ViewBag.ReasonSortParm = sortOrder == "Reason" ? "Reason_desc" : "Reason";
ViewBag.AccessSortParm = sortOrder == "Access" ? "Access_desc" : "Access";
ViewBag.UserOrAdminSortParm = sortOrder == "UserOrAdmin" ? "UserOrAdmin_desc" : "UserOrAdmin";
ViewBag.DepartmentSortParm = sortOrder == "Department" ? "Department_desc" : "Department";
ViewBag.UNCPathSortParm = sortOrder == "UNCPath" ? "UNCPath_desc" : "UNCPath";
if (searchString != null)
{
page = 1;
}
else
{
searchString = currentFilter;
}
ViewBag.CurrentFilter = searchString;
var request = from c in _context.RaidRequest
select c;
if (!String.IsNullOrEmpty(searchString))
{
request = request.Where(s => s.NameSurname.Contains(searchString));
}
request = sortOrder switch
{
"NameSurname_desc" => request.OrderByDescending(c => c.NameSurname),
"Reason" => request.OrderBy(c => c.Reason),
"Reason_desc" => request.OrderByDescending(c => c.Reason),
"Access" => request.OrderBy(c => c.Access),
"Access_desc" => request.OrderByDescending(c => c.Access),
"UserOrAdmin" => request.OrderBy(c => c.UserOrAdmin),
"UserOrAdmin_desc" => request.OrderByDescending(c => c.UserOrAdmin),
"Department" => request.OrderBy(c => c.Department),
"Department_desc" => request.OrderByDescending(c => c.Department),
"UNCPath" => request.OrderBy(c => c.UNCPath),
"UNCPath_desc" => request.OrderByDescending(c => c.UNCPath),
_ => request.OrderBy(c => c.Id),
};
int pageSize = 10;
int pageNumber = (page ?? 1);
return View(await PaginatedList<RaidRequest>.CreateAsync(request, page ?? 1, pageSize));
}
I think the problem is with the return part. What do I need to write there for it to go back to the list successfully?