小编Ank*_*kit的帖子

在编辑模式下未选择Html.DropDownListFor值

我可以在插入时成功将值保存到数据库(标题值),但是当我在编辑模式下渲染同一视图时,标题字段必须保存所选值,但是在我的情况下,标题下拉列表没有选择任何值...不知道为什么我在标题字段保留存储的值(在后端)时没有选择任何内容的下拉菜单。

@Html.DropDownListFor(model => model.title, new SelectList(Model.titles, "Value", "Text"),"-Select-") // nothing selected on edit mode

 @Model.title //displaying the stored value which the user selected initially.
Run Code Online (Sandbox Code Playgroud)


标题值

titles = new SelectList(ListItem.getValues().ToList(), "Value", "Text").ToList();
Run Code Online (Sandbox Code Playgroud)

getValue函数

 public static List<TextValue> getValues()
      {
    List<TextValue> titles= new List<TextValue>();
    TextValue T= new TextValue();


   T.Value = "Mr";
   T.Text = "Mr";
   titles.Add(T);

    T= new TextValue();
    T.Value = "Mrs";
    T.Text ="Mrs";
       titles.Add(T);

     T= new TextValue();
   T.Value = "Miss";
   T.Text = "Miss";
    titles.Add(T);

    T= new TextValue();
    T.Value ="Other";
   T.Text = "Other";
   titles.Add(T); …
Run Code Online (Sandbox Code Playgroud)

asp.net asp.net-mvc html.dropdownlistfor asp.net-mvc-3

5
推荐指数
1
解决办法
2419
查看次数