title: How to write Users checkbox checks into multiple records in database - using MVC, C#, Razor, nHibernate
body: <p>So im trying to insert into my database the values from check boxes that the user checked. </p>
  
  <p>In my ViewModel:</p>
  
  <pre><code>    [Display(Name = "Title")]
      public string Title { get; set; }
      public IEnumerable&lt;SelectListItem&gt; UserTitlelist { get; set; }
      public IEnumerable&lt;SelectListItem&gt; Titles { get; set; }
  </code></pre>
  
  <p>In my View:</p>
  
  <pre><code> @foreach (var item in Model.Titles)
    {
      &lt;label class="managelabel" style="padding: 0 5px 0 5px;"&gt;&lt;input name="Title" type="checkbox" value="@item.Value" @checkedcheckbox&gt; @item.Text&lt;/label&gt;
    }
  </code></pre>
  
  <p>In my Controller:</p>
  
  <pre><code> var titleToInsert = new UserTitle
    {
     UserId = currentUserId,
     TitleId = model.Title[];
     };
    UserManagerService.UpdateUserTitles(titleToInsert);
  </code></pre>
  
  <p>In UserManagerService:</p>
  
  <pre><code>public static int UpdateUserTitles(UserTitle userTitle)
      {
  
          using (ITransaction transaction = Context.BeginTransaction())
          {
              foreach (var x in userTitle)
              {
                  Context.Save(userTitle);
              }
              transaction.Commit();
          }
          return 0;
      }
  </code></pre>