DropDownList SelectList SelectedValue问题 [英] DropDownList SelectList SelectedValue issue

查看:157
本文介绍了DropDownList SelectList SelectedValue问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何让ASP.NET MVC SelectList工作?

到底是什么? MVC3的DropDownList中有没有一个bug?
SelectedValue不会在标记中显示为实际选择。

What the hell is it? Is there some kind of a bug in DropDownList of MVC3? SelectedValue doesn't show up as actually selected in the markup.

我正在尝试不同的方法,没有任何作用。

I am trying different approaches, nothing works.

public class SessionCategory
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public static IEnumerable<SessionCategory> Categories
{
     get
      {
          var _dal = new DataLayer();
          return _dal.GetSesionCategories();
      }
}

@{
        var cats = Infrastructure.ViewModels.Session.Categories;
        var sl = new SelectList(cats, "Id", "Name",2);
}
@Html.DropDownList("categories", sl);


推荐答案

我想您需要将选定的值设为字符串。使用扩展方法也有一些价值。详细的这里

I think you need to make the selected value a string. There's also some value in using extension methods as detailed here.

这篇关于DropDownList SelectList SelectedValue问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆