Html.DropDownListFor()设置默认选择值MVC3

时间:2013-03-05 20:54:54

标签: asp.net-mvc-3 html-helper html.dropdownlistfor

我想在创建元素时在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)

请告诉我这是什么问题?

0 个答案:

没有答案