模型得到的初始設定值如何在下拉列表
public class SModel
{
public string ddlLocation { get; set; }
public IEnumerable<SelectListItem> locationItems { get; set; }
}
控制器
[HttpGet]
public ActionResult StudyScheduler(SModel model)
{
model.spLocationItems = FillLocation();
//Here i have to fill other dropdownlist on selected value of location.
return View();
}
private List<SelectListItem> FillLocation()
{
List<SelectListItem> items = new List<SelectListItem>();
//Fill items from DB
return items;
}
查看
@Html.DropDownListFor(x => x.ddlLocation, new SelectList(Model.locationItems, "Value", "Text"), new { @class = "cssTextbox", style = "width:90%" })
如何在下拉列表獲取一個初始值選擇並傳遞給一些函數來填充其他下拉列表。
你想獲得初始選擇的值在哪裏,在控制器中,在客戶端腳本還是...? – Laziale
在控制器 – John
第一次ddl填充後立即 – John