查看 (RelacionamentoConvidado.cshtml)
@Html.DropDownList("Foi_Emitido", (IEnumerable<SelectListItem>)ViewBag.Foi_Emitido, @SRSVP.Util.Constante.HTML_HELPER_DROPDOWN_EMPTY_VALUE, new { @class = "input-small" })
控制器(EventoConvidadoController)
ViewBag.Foi_Emitido = new SelectList(Common.SimNao(model.foi_emitido), "Value", "Text");
Common.cs(静态类)
public static List<SelectListItem> SimNao(object selectedItem)
{
List<SelectListItem> _returnList = new List<SelectListItem>();
SelectListItem _mList = new SelectListItem();
_mList = new SelectListItem() { Text = "Sim", Value = "true", Selected = selectedItem == null ? false : selectedItem.ToString().Equals("true") };
_returnList.Add(_mList);
_mList = new SelectListItem() { Text = "Não", Value = "false", Selected = selectedItem == null ? false : selectedItem.ToString().Equals("false") };
_returnList.Add(_mList);
return _returnList;
}
加载页面时,选择项目不是从我的数据库返回的选择项目。
我怎样才能做到这一点?