2015-03-17 8 views
0
<div class="form-group"> 
      @Html.LabelFor(model => model.Title, htmlAttributes: new { @class = "control-label col-md-2" }) 
      <div class="col-md-10"> 
       @Html.DropDownList("Title", new SelectList(Enum.GetValues(typeof(OnLineShoppingCart.Models.Supplier.Salutation))), "Select The Salutation", new { @class = "form-control" }) 
       @Html.ValidationMessageFor(model => model.Title, "", new { @class = "text-danger" }) 
      </div> 
     </div> 
+2

Можете ли вы определить _does не work_ точно? Вы получаете сообщение об исключении или ошибке? –

+0

это может помочь: http: //stackoverflow.com/questions/28807472/get-enum-value-to-show-on-dropdownlist-asp-net-mvc –

+0

хорошо, когда я нахожусь на экране ввода, и я нажимаю enter без заполняя любые детали в полях, например, имя, фамилия, эти заполнения дают мне сообщение об ошибке, но не DropDownList – Salsero

ответ

2

попробовать это:

Контроллер

 IEnumerable<SelectListItem> TitleList = null; 
     TitleList = (from m in Enum.GetValues(typeof(Titles)).Cast<Titles>() select m).AsEnumerable().Select(m => new SelectListItem() { Text = m.ToString(), Value = m.ToString() }); 
     ViewBag.TitleList = new SelectList(TitleList, "Value", "Text"); 

Посмотреть

  <div class="form-group"> 
       @Html.LabelFor(m => m.Title, new { @class = "col-md-2 control-label" }) 
       <div class="col-md-6"> 
        @Html.DropDownListFor(m => m.Title, new SelectList(ViewBag.TitleList, "Value", "Text"), "--Select Title--", new { @class = "form-control", placeholder = "Title"})<br /> 
        @Html.ValidationMessageFor(m => m.Title, null, new { @class = "text-danger" }) 
       </div> 
      </div> 
+0

Я попробую ваш код cheers – Salsero

Смежные вопросы