我有一個DropDownListFor,它從控制器獲取數據源。有沒有辦法更新它,因爲我添加了新的值,然後我想要顯示在同一頁面上。更新DropDownListFor控制器MVC的數據源
查看:
@Html.DropDownListFor(m => m.Id, MyController.GetIds(Model.Id).Select(g => new SelectListItem { Text = g.Text, Value = g.Value }), @Resource.System_Choose, new
{
@class = "form-control selectpicker",
data_live_search = "true"
})
控制器:
public static List<SelectListItem> GetIds(int Id)
{
var retVal = new List<SelectListItem>();
return retVal;
}