title: Drop down and Radio button List for string field in MVC 4
body: <p>I have String field for Gender and Hospital Category in My MVC 4 (code First) Model Class. I want to have a radio button list for Gender showing Male and Female and Save "Male" or "Female" according to selection in my view instead of a text box which is added when generating the view. And for Hospital I want to show list of Hospital Categories in a d drop down, example, Government, Private etc. and the one selected will be saved to the Hospital Categories. I know if i use to have another class and make a relation by ID fields. but since i already have data in those fields and the application is running, I was looking for any shortcut. please help me.</p>
  
  <p>Model class:</p>
  
  <pre><code>    public class MedicalDetail
  {
      [Key]
      [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
      public int ID { get; set; }
      public string CaseNo
      {
          get
          {
              if (this.RimsMain != null)
                  return this.RimsMain.CaseNoNew;
              else
                  return "N/A";
          }
      }
      [Required]
      [ForeignKey("RimsMain")]
      public int RimsMainId { get; set; }
      public virtual RimsMain RimsMain { get; set; }
      [Required]
      public string Name { get; set; }
      [DisplayFormat(DataFormatString = "{0:d}")]
      [Column(TypeName = "DateTime2")]
      public DateTime Dob { get; set; }
      public string Nationality { get; set; }
      [DisplayFormat(DataFormatString = "{0:d}")]
      [Column(TypeName = "DateTime2")]
      [DisplayName("Examin Date")]
      public DateTime ExaminDate { get; set; }
      public string Gender { get; set; }
      [DisplayName("Referred For Hospital")]
      public string ReferredForHospital { get; set; }
      [DisplayName("Madicine Provided")]
      public string MadicineProvided { get; set; }
      public string Demand { get; set; }
      public string Reimbursement { get; set; }
      [DisplayName("Milk Assistance")]
      public string MilkAssistance { get; set; }
      [DisplayName("Chronic Case")]
      public string ChronicCase { get; set; }
      [DisplayName("Special Case")]
      public string SpecialCase { get; set; }
      [DisplayName("Gyne Case")]
      public string GyneCase { get; set; }
      [DisplayName("Referred By UNHCR")]
      public bool ReferralByUNHCR { get; set; }
      [MaxLength]
      public string LabInvestigation { get; set; }
      [MaxLength]
      public string Diagnosis { get; set; }
      public string HospitalCategory { get; set; }
      [MaxLength]
      public string Recommendation { get; set; }
      [DisplayName("Last Updated by")]
      public int? UserId { get; set; }
      [DisplayFormat(DataFormatString = "{0:d}")]
      [Column(TypeName = "DateTime2")]
      [DisplayName("Last Updated")]
      public DateTime? LastUpdated { get; set; }
  </code></pre>
  
  <p>}</p>
  
  <p>view:</p>
  
  <pre><code>        @model Rims.Models.MedicalDetail
  @{
      ViewBag.Title = "Create";
  }
  @using (Html.BeginForm())
  {
      @Html.AntiForgeryToken()
      @Html.ValidationSummary(true)
      &lt;fieldset&gt;
          &lt;legend&gt;Medical Detail&lt;/legend&gt;
          &lt;h4 style="color:@ViewBag.Color;"&gt;@ViewBag.Message&lt;/h4&gt;
          &lt;div&gt;
              &lt;div class="col2"&gt;
                  &lt;div class="editor-label"&gt;
                      &lt;label for="RimsMainId"&gt;Case No&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.RimsMain.CaseNoNew)
                      @Html.ValidationMessageFor(model =&gt; model.RimsMain.CaseNoNew)
                  &lt;/div&gt;
                  &lt;div class="editor-label"&gt;
                      &lt;label for="Name"&gt;Name&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.Name)
                      @Html.ValidationMessageFor(model =&gt; model.Name)
                  &lt;/div&gt;
                  &lt;div class="editor-label"&gt;
                      &lt;label for="Dob"&gt;DOB&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.TextBoxFor(model =&gt; model.Dob, new { @class = "form-control datepicker" })
                      @Html.ValidationMessageFor(model =&gt; model.Dob)
                  &lt;/div&gt;
  
                  &lt;div class="editor-label"&gt;
                      &lt;label for="Nationality"&gt;Nationality&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.Nationality)
                      @Html.ValidationMessageFor(model =&gt; model.Nationality)
                  &lt;/div&gt;
                  &lt;div class="editor-label"&gt;
                      &lt;label for="ExaminDate"&gt;Examin Date&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.TextBoxFor(model =&gt; model.ExaminDate, new { @class = "form-control datepicker" })
                      @Html.ValidationMessageFor(model =&gt; model.ExaminDate)
                  &lt;/div&gt;
  
                  &lt;div class="editor-label"&gt;
                      &lt;label for="Gender"&gt;Gender&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.Gender)
                      @Html.ValidationMessageFor(model =&gt; model.Gender)
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="col2"&gt;
                  &lt;div&gt;
                      &lt;div class="editor-label"&gt;
                          &lt;label for="ReferredFor"&gt;Referred by UNHCR&lt;/label&gt;
                      &lt;/div&gt;
                      &lt;div class="editor-field"&gt;
                          @Html.EditorFor(model =&gt; model.ReferralByUNHCR)
                          @Html.ValidationMessageFor(model =&gt; model.ReferralByUNHCR)
                      &lt;/div&gt;
                      &lt;div class="clear"&gt;&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-label"&gt;
                      &lt;label for="MadicineProvided"&gt;Madicine Provided&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.MadicineProvided)
                      @Html.ValidationMessageFor(model =&gt; model.MadicineProvided)
                  &lt;/div&gt;
                  &lt;div class="editor-label"&gt;
                      &lt;label for="MilkAssistance"&gt;Milk Assistance&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.MilkAssistance)
                      @Html.ValidationMessageFor(model =&gt; model.MilkAssistance)
                  &lt;/div&gt;
                  &lt;div class="editor-label"&gt;
                      &lt;label for="MilkAssistance"&gt;Chronic Case&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.ChronicCase)
                      @Html.ValidationMessageFor(model =&gt; model.ChronicCase)
                  &lt;/div&gt;
                  &lt;div class="editor-label"&gt;
                      &lt;label for="MilkAssistance"&gt;Special Case&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.SpecialCase)
                      @Html.ValidationMessageFor(model =&gt; model.SpecialCase)
                  &lt;/div&gt;
                  &lt;div class="editor-label"&gt;
                      &lt;label for="MilkAssistance"&gt;Gyne Case&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.GyneCase)
                      @Html.ValidationMessageFor(model =&gt; model.GyneCase)
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="clear"&gt;&lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="editor-label"&gt;
              &lt;label for="Demand"&gt;Demand&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextAreaFor(model =&gt; model.Demand, 5, 70, new { @class = "txtArea" })
              @Html.ValidationMessageFor(model =&gt; model.Demand)
          &lt;/div&gt;
          &lt;div class="editor-label"&gt;
              &lt;label for="ReimbursemenT"&gt;Reimbursement&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextAreaFor(model =&gt; model.Reimbursement, 5, 70, new { @class = "txtArea" })
              @Html.ValidationMessageFor(model =&gt; model.Reimbursement)
          &lt;/div&gt;
          &lt;div class="editor-label"&gt;
              &lt;label for="Referred"&gt;Referred for Hospital&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextAreaFor(model =&gt; model.ReferredForHospital, 5, 70, new { @class = "txtArea" })
              @Html.ValidationMessageFor(model =&gt; model.ReferredForHospital)
          &lt;/div&gt;
           &lt;div class="editor-label"&gt;
              &lt;label for="Remarks"&gt;Lab Investigation&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextAreaFor(model =&gt; model.LabInvestigation, 5, 70, new { @class = "txtArea" })
              @Html.ValidationMessageFor(model =&gt; model.LabInvestigation)
          &lt;/div&gt;
           &lt;div class="editor-label"&gt;
              &lt;label for="Remarks"&gt;Diagnosis&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextAreaFor(model =&gt; model.Diagnosis, 5, 70, new { @class = "txtArea" })
              @Html.ValidationMessageFor(model =&gt; model.Diagnosis)
          &lt;/div&gt;
  
           &lt;div class="editor-label"&gt;
              &lt;label for="Remarks"&gt;Hospital Category&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextAreaFor(model =&gt; model.HospitalCategory, 5, 70, new { @class = "txtArea" })
              @Html.ValidationMessageFor(model =&gt; model.HospitalCategory)
          &lt;/div&gt;
          &lt;div class="editor-label"&gt;
              &lt;label for="Remarks"&gt;Recommendation&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextAreaFor(model =&gt; model.Recommendation, 5, 70, new { @class = "txtArea" })
              @Html.ValidationMessageFor(model =&gt; model.Recommendation)
          &lt;/div&gt;
  
          &lt;p id="otherButtons1"&gt;
              &lt;input type="submit" value="Create" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  }
  &lt;div id="otherButtons"&gt;
      @Html.ActionLink("Back to List", "Index")
  &lt;/div&gt;
  </code></pre>
  
  <p>In the Above view I want to replace the the following Field by Two Radio Buttons that is Male and Female</p>
  
  <pre><code>&lt;div class="editor-label"&gt;
                      &lt;label for="Gender"&gt;Gender&lt;/label&gt;
                  &lt;/div&gt;
                  &lt;div class="editor-field"&gt;
                      @Html.EditorFor(model =&gt; model.Gender)
                      @Html.ValidationMessageFor(model =&gt; model.Gender)
                  &lt;/div&gt;
  </code></pre>
  
  <p>And The Following field by a drop down which will have some values. for example "Gov", "Private" etc.</p>
  
  <pre><code> &lt;div class="editor-label"&gt;
              &lt;label for="Remarks"&gt;Hospital Category&lt;/label&gt;
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextAreaFor(model =&gt; model.HospitalCategory, 5, 70, new { @class = "txtArea" })
              @Html.ValidationMessageFor(model =&gt; model.HospitalCategory)
          &lt;/div&gt;
  </code></pre>
  
  <p>also I want to know how can i save the value in Create Action:</p>
  
  <pre><code>[HttpPost]
          [Authorize(Roles = "Admin,Medical")]
          [ValidateAntiForgeryToken]
          public ActionResult Create(MedicalDetail medicaldetail)
          {
              if (ModelState.IsValid)
              {
                  var rimsMain = db.RimsMains.Where(x =&gt; x.CaseNoNew == medicaldetail.RimsMain.CaseNoNew).FirstOrDefault();
                  if (rimsMain == null)
                  {
                      ViewBag.Message = "Invalid Case Number!";
                      ViewBag.Color = "Red";
                      return View(medicaldetail);
                  }
                  else
                  {
                      medicaldetail.RimsMainId = rimsMain.Id;
                      //medicaldetail.RimsMain = rimsMain;
                      medicaldetail.LastUpdated = DateTime.Now;
                      medicaldetail.UserId = WebSecurity.CurrentUserId;
                      db.MedicalDetails.Add(medicaldetail);
                      db.SaveChanges();
                      return RedirectToAction("Create", new { message = "Record Added Successfully!", color = "Green" });
                  }
              }
  
              return View(medicaldetail);
          }
  </code></pre>