更新时间:2023-02-16 11:12:24
我使用List我的下拉列表。要做到这样,你可以建立你的控制器上的列表这样
I use List for my dropdown list. to do it that way you can build the list like this on your controller
List<SelectListItem> ls = new List<SelectListItem>();
foreach(var temp in Movies){
ls.Add(new SelectListItem() { Text = temp.Text, Value = temp.Value });
}
Movie.MovieList = ls;
您只能传递模型视图。从code你逝去的电影模式,使放
you can only pass one model to the view. from your code you are passing the movie model so put
public List<SelectListItem> MovieList { get; set; }
在您的模型。然后在视图中,可以建立你的DropDownList像这样
in your model. Then on the view you can build your dropdownlist like this
@Html.DropDownListFor(x => x.Id, Model.MovieList)
让我知道,如果你有任何问题。
Let me know if you have any questions.