Asp.net mvc 过滤器下拉列表MVC4
我是MVC新手。我想使用Dropdownlist中的参数筛选我的表: 我的模型:Asp.net mvc 过滤器下拉列表MVC4,asp.net-mvc,asp.net-mvc-5,Asp.net Mvc,Asp.net Mvc 5,我是MVC新手。我想使用Dropdownlist中的参数筛选我的表: 我的模型: public class Document { [Key] public int MasterAPID { get; set; } public string CompanyID { get; set; } public MasterCompany MasterCompany { get; set; } public string Year { get; set; }
public class Document
{
[Key]
public int MasterAPID { get; set; }
public string CompanyID { get; set; }
public MasterCompany MasterCompany { get; set; }
public string Year { get; set; }
public string Month { get; set; }
public string DocumentNumber { get; set; }
}
public class MasterCompany
{
[Key]
public string CompanyID { get; set; }
public string CompanyName { get; set; }
}
我的控制器:
private IRMAContext db = new IRMAContext();
// GET: MasterAPs
public ActionResult Index()
{
ViewBag.CompanyID = new SelectList(db.MasterCompanies, "CompanyID", "CompanyName");
var masterAPs = db.MasterAPs.Include(m => m.MasterCompany);
return View(masterAPs.ToList());
}
我的看法是:
@Html.DropDownList("CompanyID", null, htmlAttributes: new { @class = "form-control" })
@Html.DropDownList("oYear", Enumerable.Range(DateTime.Now.Year, 10).Select(x => new SelectListItem { Text = x.ToString() }), "Select Year", new { @class = "form-control" })
@Html.DropDownList("oMonth", Enumerable.Range(1, 12).Select(x => new SelectListItem { Text = x.ToString("00") }), "Select Month", new { @class = "form-control" })
<br>
<button type="submit">View</button>
<table>
<tr>
<th>
@Html.DisplayNameFor(model => model.DocumentNumber)
</th>
</tr>
</table>
@Html.DropDownList(“CompanyID”,null,htmlAttributes:new{@class=“form control”})
@DropDownList(“oYear”,Enumerable.Range(DateTime.Now.Year,10)。选择(x=>new SelectListItem{Text=x.ToString()}),“选择年份”,新建{@class=“form control”})
@DropDownList(“oMonth”,Enumerable.Range(1,12)。选择(x=>newselectListItem{Text=x.ToString(“00”),“选择月份”,新建{@class=“form control”})
看法
@DisplayNameFor(model=>model.DocumentNumber)
因此,在表本身上,我不会显示这3个参数。只有DocumentNumber
字段。当用户选择公司
,年
,月
,然后单击查看按钮时,表格将自动仅显示基于所选参数的数据。我怎样才能做到这一点?
非常感谢。您可以在控制器上添加另一个操作,以及与该操作匹配的另一个视图。例如:
// GET: Detials
public ActionResult Details(int companyId)
{
ViewBag.CompanyID = new SelectList(db.MasterCompanies, "CompanyID", "CompanyName");
var specificCompany = db.MasterAPs.Include(m => m.MasterCompany).Where(c => c.Id == companyId);
return View(specificCompany);
}
并根据需要使用传递的数据编辑新的Details.cshtml。我应该在按钮视图上放置什么?您可以放置