HTML.DropDownListFor选定的问题

时间:2014-05-01 18:01:27

标签: c# razor selected html.dropdownlistfor

我已经阅读了有关此主题的各种帖子,但没有一个是正确的。我只是试图设置" 30"价值为"选择"。 SelectListItem具有值,文本并被选为可用参数,但被选中并没有做我能看到的任何事情。

@Html.DropDownListFor(model => model.IndexThreshold, new List<SelectListItem>() { new SelectListItem() { Text = "0", Value = "0" }, new SelectListItem() { Text = "10", Value = "10" }, new SelectListItem() { Text = "20", Value = "20" }, new SelectListItem() { Selected = true, Text = "30", Value = "30", Selected = true}, new SelectListItem() { Text = "40", Value = "40" }, new SelectListItem() { Text = "50", Value = "50" } }, HtmlAttr.Create("value: IndexThreshold", isReadOnly))


[DataMember]
public int IndexThreshold { get; set; }


public class SelectListItem
{
    public SelectListItem();
    public bool Selected { get; set; }
    public string Text { get; set; }
    public string Value { get; set; }
}

我确定我做错了(这是现有的代码,我只是试图实现“已选择的”功能)。任何有关如何清理/解决此问题的建议将不胜感激。

旁注:我对这种语言很新,但不是编程,所以请耐心等待,因为我偶然发现了语法和实现。 :)

谢谢,

0 个答案:

没有答案