我在mvc3 Razor中绑定下拉列表。 我的问题是它没有显示默认的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\", Arial, sans-serif", Selected = true });
FontType.Add(new SelectListItem() { Text = "\"Palatino Linotype\", Times, serif", Value = "\"Palatino Linotype\", Times, serif" });
FontType.Add(new SelectListItem() { Text = "\"Times New Roman\", Times, serif", Value = "\"Times New Roman\", Times, serif" });
return FontType;
}
}
答案 0 :(得分:1)
在渲染此视图的控制器操作中:
public ActionResult Index()
{
var model = ...
model.MainHeadingFont = "\"Palatino Linotype\", Times, serif";
return View(model);
}
这将自动预选ddl的第二个元素。