title: populate radiobuttonlist from database table in asp.net mvc
body: <p><a href="https://i.stack.imgur.com/wecYf.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wecYf.jpg" alt="enter image description here"></a></p>
  
  <p>I want to create a form like above, </p>
  
  <p>also have to populate Viewer User Groups accodrding to <strong>UserGroups</strong> table
  <a href="https://i.stack.imgur.com/nS9U4.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nS9U4.jpg" alt="enter image description here"></a></p>
  
  <pre><code>public partial class UserGroup
  {
      public string UserGroup_ID { get; set; }
      public string UserGroupNameEn { get; set; }
  }
  </code></pre>
  
  <p>So populate this user groups and get the filled data I created new model (so it can apply to view (1st image))</p>
  
  <p>I followed theses Stack overflow <a href="https://stackoverflow.com/questions/5768274/correct-way-to-bind-an-mvc3-radiobutton-to-a-model">question 1</a> and  <a href="https://stackoverflow.com/questions/6638966/mvc-radiobutton-binding-complex-object">question 2</a> to make this</p>
  
  <p>this is controller class for this</p>
  
  <pre><code>    [HttpGet]
      public ActionResult ProductFields_Create()
      {
          var model = new ProductFields
          {
              LisGroups = GetUserGroupListEn()
          };
  
          return View(model);
  
      }
  
      public MultiSelectList GetUserGroupListEn()
      {
          return new MultiSelectList(db.UserGroup.ToList(), "UserGroup_ID", "UserGroupNameEn");
      }
  
      [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult ProductFields_Create(ProductFields product_fields)
      {
        ...........
      }
  </code></pre>
  
  <p>this is model class for first image</p>
  
  <pre><code>public class ProductFields
  {
      public string ProductFieldID { get; set; }
      public string ProductFieldNameEn { get; set; }
      public string ProductFieldNameAr { get; set; }
      public string ProdcutFieldDiscriptionEn { get; set; }
      public string ProductFieldDiscriptionAr { get; set; }
  
      public List&lt;UserGroup&gt; LisGroups { get; set; }
  
      [Required]
      public string SelectedGroupID { get; set; }
  }
  </code></pre>
  
  <p>viewpage for above view </p>
  
  <pre><code>@model Project_Name.Models.ProductFields
  
  @using (Html.BeginForm())
  {
  
      &lt;fieldset&gt;
           &lt;div class="form-horizontal"&gt;           
  
              @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  
              .....
  
               &lt;div class="form-group"&gt;
               &lt;div&gt;
                   @Html.ValidationMessageFor(x =&gt; x.SelectedGroupID)
                   foreach (var group in Model.LisGroups)
                   {
                   &lt;div&gt;
                       @Html.RadioButtonFor(x =&gt; x.SelectedGroupID, group.UserGroup_ID, new { id = "emp" + group.UserGroup_ID })
                       @Html.Label("emp" + group.UserGroup_ID, employee.Label)
                   &lt;/div&gt;
                   }
  
               &lt;/div&gt;
  
            &lt;/div&gt;
  
             &lt;div class="form-group"&gt;
                  &lt;div class="col-md-offset-2 col-md-10"&gt;
                      &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
                  &lt;/div&gt;
             &lt;/div&gt;
  
  
          &lt;/div&gt;
      &lt;/fieldset&gt;
  }
  </code></pre>
  
  <p>but here I'm getting major errors with red squiggly lines</p>
  
  <blockquote>
    <p>The name 'group' does not exist in the current context</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/VZ3Xa.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VZ3Xa.jpg" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>Cannot implicitly convert type 'System.Web.Mvc.MultiSelectList' to 'System.Collections.Generic.List'</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/xLMHF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xLMHF.jpg" alt="enter image description here"></a></p>