Asp.NetMVC |下拉列表数据提取
Asp.Net MVC | Dropdownlist data extraction
如何将相关的sql数据拉到下面的下拉列表中进行控制?下拉列表应默认为“m.alici”数据。
<div class="form-group">
<label for="exampleInputEmail3">Müşteri Adı Soyadı</label>
@Html.TextBoxFor(m => m.Alici, new { @class = "form-control" })
</div>
<div class="form-group">
<label for="exampleInputPassword4">Sipariş Adresi</label>
@Html.TextAreaFor(m => m.adres, new { @class = "form-control" })
</div>
<div class="form-group">
<label for="exampleSelectGender">Sipariş Durumu</label>
@Html.DropDownListFor(m=>m.Durum
</div>
在您的控制器中创建一个 ViewBag。注意最后一个参数可以加上默认值
ViewBag.Example = new SelectList((from s in _cs.example.OrderBy(s => s.Code)
select new { ID = s.Id, FullDescription = s.Code + " - " + s.Description }),"ID",
"FullDescription","m.alici");
然后在你看来
@Html.DropDownListFor(m => m.Durum, (SelectList)ViewBag.Example, new { @class = "form-control" })
如何将相关的sql数据拉到下面的下拉列表中进行控制?下拉列表应默认为“m.alici”数据。
<div class="form-group">
<label for="exampleInputEmail3">Müşteri Adı Soyadı</label>
@Html.TextBoxFor(m => m.Alici, new { @class = "form-control" })
</div>
<div class="form-group">
<label for="exampleInputPassword4">Sipariş Adresi</label>
@Html.TextAreaFor(m => m.adres, new { @class = "form-control" })
</div>
<div class="form-group">
<label for="exampleSelectGender">Sipariş Durumu</label>
@Html.DropDownListFor(m=>m.Durum
</div>
在您的控制器中创建一个 ViewBag。注意最后一个参数可以加上默认值
ViewBag.Example = new SelectList((from s in _cs.example.OrderBy(s => s.Code)
select new { ID = s.Id, FullDescription = s.Code + " - " + s.Description }),"ID",
"FullDescription","m.alici");
然后在你看来
@Html.DropDownListFor(m => m.Durum, (SelectList)ViewBag.Example, new { @class = "form-control" })