0

我想在创建元素时在 DropDownListFor 中设置默认选择值

数据模型:

public class CascadingDropDownModel
{
    public int? PreviousFirstListId { get; set; }
    public int? SelectedFirstListId { get; set; }
    public int? SelectedSecondListId { get; set; }

    public string FirstTextHint { get; set; }
    public string SecondTextHint { get; set; }

    public IList<DropDownElement> FirstDropDownData { get; set; }
    public IList<DropDownElement> SecondDropDownData { get; set; }

    public CascadingDropDownModel()
    {
        FirstDropDownData = new List<DropDownElement>();
        SecondDropDownData = new List<DropDownElement>();
    }
}

部分视图(不起作用):

 @Html.DropDownListFor(
                m => m.SelectedFirstListId,
                new SelectList(Model.FirstDropDownData, "Id", "Name", Model.SelectedFirstListId),
                Model.FirstTextHint)

部分观点(作品):

 @Html.DropDownListFor(
                m => m.SelectedFirstListId,
                new SelectList(Model.FirstDropDownData, "Id", "Name", 5),
                Model.FirstTextHint)

请告诉我是什么问题?

4

0 回答 0