在除錯我的應用程式時,我在 Action Method 中放置了一個斷點,因為排序不起作用。出于某種原因,即使我單擊 Course HTML 鏈接,sortOrder 引數仍保持為空。目標是當用戶單擊 htmllink 時,課程名稱應按降序過濾,該降序可以來自 switch 陳述句
行動方法:
[HttpGet]
public ActionResult TranscriptAdmin(int id, string sortOrder, string currentFilter, string searchString, int? page)
{
ViewBag.CurrentSort = sortOrder;
ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
if (searchString != null)
{
page = 1;
}
else
{
searchString = currentFilter;
}
ViewBag.CurrentFilter = searchString;
StudentMajorRepo sRepo;
MajorRequirmentsRepo mRepo;
GradesRepo gRepo;
RegistrationRepo rRepo;
TranscriptViewModel viewModel = new TranscriptViewModel();
viewModel.StudentId = id;
IList<Grade> AllClasses = new List<Grade>();
IList<Registration> AllRegistrations = new List<Registration>();
IList<Registration> PendingGrades = new List<Registration>();
using (context)
{
sRepo = new StudentMajorRepo(context);
mRepo = new MajorRequirmentsRepo(context);
gRepo = new GradesRepo(context);
rRepo = new RegistrationRepo(context);
viewModel.AllGradesClasses = gRepo.GetAllGradesByUserId(id);
viewModel.StudentMajor = sRepo.GetByStudentId(id);
}
switch (sortOrder)
{
case "name_desc":
viewModel.AllGradesClasses.OrderByDescending(c => c.Registration.CourseSection.Course.CourseTitle);
break;
default: // Name ascending
break;
}
int pageSize = 3;
int pageNumber = (page ?? 1);
return View(viewModel);
}
剃須刀頁面:
<div class="col-md-6">
<table class="table table-striped table-dark">
<thead class="thead-dark">
<tr>
<th>Course Id</th>
<th>@Html.ActionLink("Course", "TranscriptAdmin", "Student", new { studentId = Model.StudentId}, new { sortOrder = ViewBag.NameSortParm })</th>
<th>Credits</th>
<th>Grade</th>
<th>Semester</th>
</tr>
</thead>
uj5u.com熱心網友回復:
將您更改ActionLink為:
<th>@Html.ActionLink("Course", "TranscriptAdmin", "Student", new { studentId = Model.StudentId, sortOrder = ViewBag.NameSortParm}, null)</th>
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/441295.html
標籤:C# 。网 asp.net-mvc 视觉工作室
