2016-08-16 3 views
0

私は自分のモデルとコントローラをデータベースから取得し、コントローラからビューを生成しました。背景の背景を説明するために、ユーザーが特定のサービスに関するレビューを投稿したり編集したりするためのアプリケーションを作成しました。ユーザーがレビューを作成したりレビューを編集するための「作成」と「編集」ビューを作成しました。作成ビューでフォーム・グループの一部では、ユーザーは、彼らがドロップダウンリストの編集レビュー

<div> 
       <div class="form-group"> 
        @Html.LabelFor(model => model.WellnessService, htmlAttributes: new { @class = "control-label col-md-2" }) 
        <div class="col-md-10"> 
         @Html.DropDownList("WellnessService", new List<SelectListItem> 
       { 
        new SelectListItem() {Text = "Student Wellness Service", Value = "Student Wellness Service"}, 
        new SelectListItem() {Text = "HAICU", Value = "HAICU"}, 
        new SelectListItem() {Text = "Student Counceling", Value = "Student Counceling"}, 
        new SelectListItem() {Text = "DISCHO (Discrimination and Harassment Office)", Value = "DISCHO"}, 
        new SelectListItem() {Text = "Campus Protection Service (CPS)", Value = "CPS"}, 
        new SelectListItem() {Text = "Disablity Service", Value = "Disability Service"}, 
       }, "Select Wellness Service") 



         @Html.ValidationMessageFor(model => model.WellnessService, "", new { @class = "text-danger" }) 
        </div> 
       </div> 
      </div> 

を確認したいサービスを選択することができますが、編集ビューでは、ユーザーは、彼または彼女が喜ば何にサービスの価値ことができます。私はあなたのことを読んだP

:私はそれが理にかなっている場合のみ、それらの代わりに、私は与えるドロップダウンに基づく審査のサービス名を変更することにユーザーが

<div class="form-group"> 
         @Html.LabelFor(model => model.Rating, htmlAttributes: new {@class = "control-label col-md-2"}) 
         <div class="col-md-10"> 
          @Html.EditorFor(model => model.Rating, new {htmlAttributes = new {@class = "form-control"}}) 
          @Html.ValidationMessageFor(model => model.Rating, "", new {@class = "text-danger"}) 
         </div> 
        </div> 

を入力したいですあなたのモデルで列挙子をセットアップする必要がありますが、これは利用可能なガイドがありましたが、これは最初のmvc5コードであり、データベースではありません。

答えて

0

多くの方法があります。 modelあなたのViewModelに、あなたはIEnumerable<WellnessService> WellnessService { get; set; }を作成することができますし、この

var services = new List <SelectListItem> { 
    new SelectListItem() { 
      Text = "Student Wellness Service", Value = "Student Wellness Service" 
     }, 
     new SelectListItem() { 
      Text = "HAICU", Value = "HAICU" 
     }, 
     new SelectListItem() { 
      Text = "Student Counceling", Value = "Student Counceling" 
     }, 
     new SelectListItem() { 
      Text = "DISCHO (Discrimination and Harassment Office)", Value = "DISCHO" 
     }, 
     new SelectListItem() { 
      Text = "Campus Protection Service (CPS)", Value = "CPS" 
     }, 
     new SelectListItem() { 
      Text = "Disablity Service", Value = "Disability Service" 
     }, 
} 
model.WellnessServices = services; 

それとも、あなたのViewBagに入れて、このよう

ViewBag.WellnessServices = services; 
を渡すことができるようにそれを渡します
関連する問題