title: Get radiobutton selected according to value in database using mvc3
body: <p>i have a radiobutton list in my create view.It is generated along with checkbox when selecting a dropdown.</p>
  
  <pre><code>@model IEnumerable&lt;Admin.Models.viewmodel&gt;
  @foreach (var item in Model)
  {
      &lt;label&gt;
             @Html.CheckBox("User", item.Selected, new { @id = "User" + item.Value, @value = item.Value })
              @item.Text
      &lt;/label&gt;
      &lt;label&gt;
          @Html.RadioButton("rdnUser" + item.Value.TrimStart(), 1, item.IsSelected,new { @id = "rdnUser"})Primary                  
  
      &lt;/label&gt;
      &lt;label&gt;
         @Html.RadioButton("rdnUser" + item.Value.TrimStart(), 2,item.IsSelected, new { @id = "rdnUser"})Secondary
      &lt;/label&gt;
  }
  </code></pre>
  
  <p>Iam saving the value of radiobutton to a field UserType in table UserMapping.</p>
  
  <p>When I click on Edit link,I want to get the radiobutton selected according to database value..</p>
  
  <p>Created a viewmodel to take values in checkbox and radiobutton.viewpartial viewmodel is:-</p>
  
  <pre><code>public class viewpartial : System.Web.Mvc.SelectListItem
      {
          public int Values { get; set; }
          public bool IsSelected { get; set; }
      }
  </code></pre>
  
  <p>The query is:-</p>
  
  <pre><code>var query = (from u in UserMapping
                                  where u.UserID == id &amp;&amp; u.Active == 1
                                  join f in Financial on u.FinancialID equals f.FinancialID
                                into c
                                  from d in c.DefaultIfEmpty()
                                  select new viewpartialIFC
                                  {
                                      Text = d.FiName,
                                      Value = SqlFunctions.StringConvert((double)d.FinancialID),
                                      Selected = d.FinancialID == u.FinancialID ? true : false,
                                      Values = u.UserType,
                                    //IsSelected=???
                                  }).Distinct().ToList();
  </code></pre>
  
  <p>what changes should i make in the query to get radiobutton selected..</p>