我正在尝试在 ASP.NET MVC 中执行下拉筛选内容。我希望下拉列表显示三种毕业状态(已毕业、通过、未通过),当我选择一个时,它只会显示所选状态的学生!
控制器:
ViewBag.GraduationStatus = new SelectList(db.Graduated_Students, "Graduated Status");
var graduates = db.Graduated_Students.Where(student => student.GraduationStatus != null);
return View(graduates.ToList());
看法:
@using (Html.BeginForm())
{
<table>
<tr>
<th>
@Html.DropDownList("GraduationStatus", null, htmlAttributes: new { @class = "form-control" })
</th>
<th>
<input type="submit" value="Filter by graduation Status" />
</th>
</tr>
</table>
}
模型 :
namespace CodeboxxSchoolPortal
{
using System;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
public partial class Graduated_Students
{
public int ID { get; set; }
public int CohortId { get; set; }
public string GraduationStatus { get; set; }
public string Name { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string ContractStatus { get; set; }
public string DepositStatus { get; set; }
public Nullable<int> PartnerId { get; set; }
public string PartnerName { get; set; }
public List<SelectListItem> GraduationStatusList = new List<SelectListItem>
{
new SelectListItem { Value="Graduated", Text="Graduated" },
new SelectListItem { Value ="Pass", Text="Pass" },
new SelectListItem { Value ="Failed", Text="Failed" }
};
public class SelectListItem
{
public string Value { get; set; }
public string Text { get; set; }
}
}
}
胡子哥哥
相关分类