[英]ASP.NET MVC - How to transfer the selected item from DropDownListFor to the Controller
I'm making a DropDownListFor
and pulling its items with the model.我正在制作一个
DropDownListFor
并使用 model 拉动它的项目。
But I cannot transfer the selected item from DropDownListFor
to the controller.但我无法将所选项目从
DropDownListFor
转移到 controller。
Index.cshtml:索引.cshtml:
@using (Html.BeginForm("Index", "StudentTable", FormMethod.Get))
{
<p>
<p>Class:</p>
<div class="form-group">
<select class="form-control" id="SelectedId">
@foreach (var item in Model)
{
<option value="@item.ClassId">@item.Class.ClassName</option>
}
</select>
</div>
<input type="submit" value="Ara">
</p>
}
Controller: Controller:
StudentDatabaseContext db = new StudentDatabaseContext();
public ActionResult Index(string SelectedId)
{
var studentList = db.StudentTables.Include(x => x.Class).ToList();
var degerler = from d in db.StudentTables select d;
if (!string.IsNullOrEmpty(SelectedId))
{
degerler = degerler.Where(m => m.ClassId.ToString().Contains(SelectedId));
}
return View(degerler.ToList());
}
What is the problem?问题是什么? How can I solve it?
我该如何解决? Thanks for the help.
谢谢您的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.