我正在尝试使用下拉列表过滤列表视图。
我的控制器:
public async Task<ActionResult> Index(int? TradeExerciseNumber)
{
var TradeExerciseEntries = new TradeExerciseController().GetAll();
ViewBag.TradeExerciseEntries = new SelectList(TradeExerciseEntries, "TradeExerciseID", "TradeExerciseNumber");
if (TradeExerciseNumber != null)
{
return View(await db.TradesModels.Where(x => x.TradeExerciseId == TradeExerciseNumber).ToListAsync());
}
return View(await db.TradesModels.ToListAsync());
}
我的观点:
@using (Html.BeginForm())
{
<p>
Find by Exercise Number: @Html.DropDownList("TradeExerciseEntries", -how do I pass value to TradeExerciseNumber in my controller to let it render pls- )
<input type="submit" value="Search" />
</p>
}
现在,如何将下拉列表值传递给控制器中的TradeExerciseNumber
以便让它渲染?非常感谢你。
祝你好运
答案 0 :(得分:0)
所以这就是我在我看来所做的事情,它起作用了:
@using (Html.BeginForm("Index", "Trades")){
<p>
Find by Exercise Number: @Html.DropDownList("TradeExerciseNumber", ViewBag.TradeExerciseEntries as SelectList, null, new { onchange = "submit();" })
</p>
}
我希望它有所帮助。感谢