微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在mvc3 Razor中绑定dropdownlist未选择默认的Dropdownlist值

如何解决在mvc3 Razor中绑定dropdownlist未选择默认的Dropdownlist值

| 我在mvc3 Razor中绑定dropdownlist。 我的问题是它没有显示认的Dropdownlist值,显示为空。 代码如下:
  @Html.DropDownListFor(model => model.MainheadingFont,new SelectList(Model.lst_FontType,\"Value\",\"Text\"),new { @class = \"inputPage7Select\" })
CollectionList是从Model传递的:
public List<SelectListItem> lst_FontType
    {
        get
        {
            FontType.RemoveRange(0,FontType.Count);
            FontType.Add(new SelectListItem() { Text = \"\\\"Gill Sans MT\\\",Arial,sans-serif\",Value = \"\\\"Gill Sans MT\\\",Selected = true });
            FontType.Add(new SelectListItem() { Text = \"\\\"Palatino Linotype\\\",Times,serif\",Value = \"\\\"Palatino Linotype\\\",serif\" });
            FontType.Add(new SelectListItem() { Text = \"\\\"Times New Roman\\\",Value = \"\\\"Times New Roman\\\",serif\" });
            return FontType;
        }
    }  
    

解决方法

在呈现该视图的控制器操作中:
public ActionResult Index()
{
    var model = ...
    model.MainHeadingFont = \"\\\"Palatino Linotype\\\",Times,serif\";
    return View(model);
}
这将自动预选ddl的第二个元素。     

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。