title: How to count total of leaves(fetching from database) of each user  separately in MVC-3?
body: <p>I wants to count the total leaves of each users from the database.
  and wants to display it in telerik gridview in <b>Asp.Net MVC-3 (Aspx)</b>.</p>
  
  <p>i have a gridview with two columns. first column displays the names of all the employees/users and 2nd column will display the total leaves of that users.</p>
  
  <p>my <b>database</b> is as below</p>
  
  <p><b>leave_master</b></p>
  
  <p>leave_id (primary key)
  user_id  (foreign key with user_id of table user_master)
  leave_days</p>
  
  <p><b>user_master</b></p>
  
  <p>user_id (primary key)
  user_real_name</p>
  
  <p>My Model files are as below</p>
  
  <p>name - <b>LeaveGridview.cs</b></p>
  
  <pre><code>&lt;pre&gt;
  
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.ComponentModel.DataAnnotations;
  using System.ComponentModel;
  
  
  namespace ProjectManagementSystem.Models
  {
      public class LeaveGridview
      {
  
          public int user_id { get; set; }
  
          public string user_name { get; set; }
  
          public string user_real_name { get; set; }    
  
          public int leave_id { get; set; }
  
          public decimal leave_days { get; set; }
  
  
      }
  }
  &lt;/pre&gt;
  </code></pre>
  
  <p>2nd file </p>
  
  <p>name - <b>LeaveGridviewFetch.cs</b></p>
  
  <pre><code>&lt;pre&gt;
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  
  namespace ProjectManagementSystem.Models
  {
  
      public class LeaveGridviewFetch
      {
  
  
  
          public static IList&amp;lt;LeaveGridview&amp;gt; all()
          {
              IList&amp;lt;LeaveGridview&amp;gt; result =
                  (IList&amp;lt;LeaveGridview&amp;gt;)HttpContext.Current.Session["leave1"];
  
              if (result == null)
              {
  
                  HttpContext.Current.Session["leave1"] = result =
                      (from l in new ProjectManagementSystemEntities3().leave_master
                       select new LeaveGridview
                       {
                           user_id = l.user_id,
                           leave_id = l.leave_id,
                           user_real_name = l.user_master.user_real_name,
  
  
  
                       }).ToList();
  
              }
              return result;
          }
      }
  }
  &lt;/pre&gt;
  </code></pre>
  
  <p>My contgroller file 
  name <b>LeaveController.cs</b></p>
  
  <pre><code>&lt;pre&gt;
  
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  using ProjectManagementSystem.Models;
  using Telerik.Web.Mvc;
  
  namespace LeaveModule.Controllers
  {
      public class LeaveController : Controller
      {
          public ProjectManagementSystemEntities3 pb = new ProjectManagementSystemEntities3();
  
    public ActionResult LeaveShow()
          {
              var leave_master = pb.leave_master.Include("user_master");
              ViewBag.leave_id = new SelectList(pb.user_master, "user_id", "user_real_name");
              return View(leave_master.ToList());
          }
  
   [GridAction]
          public ActionResult _SelectBatchEditing()
          {
              return View(new GridModel(LeaveGridviewFetch.all()));
          }
  
  }
  }
  
  &lt;/pre&gt;
  </code></pre>
  
  <p>my view is </p>
  
  <p>name <b>LeaveShow.ascx</b></p>
  
  <pre><code>&lt;pre&gt;
  
  &amp;lt;%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %&amp;gt;
  
  &amp;lt;asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"&amp;gt;
      LeaveShow
  &amp;lt;/asp:Content&amp;gt;
  
  &amp;lt;asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"&amp;gt;
  
  &amp;lt;%  Html.Telerik().Grid&amp;lt;ProjectManagementSystem.Models.LeaveGridview&amp;gt;() 
                         .Name("grid")
                         .DataKeys(keys =&amp;gt;
                         {
                             keys.Add(l =&amp;gt; l.leave_id);
                         })
  
                         .DataBinding(dataBinding =&amp;gt;
                          dataBinding.Ajax()
                         .Select("_SelectBatchEditing", "Leave") // Leave is controller name
                         )
  
                          .Columns(columns =&amp;gt;
                         {
  
                             columns.Bound(l =&amp;gt; l.user_real_name).Width(200); 
  
                             columns.Bound(l =&amp;gt; l.leave_days).Width(150);
  
                         })
  
  
                         .Groupable()
                         .Pageable()
                         .Filterable()
                         .Render();
  
                         %&amp;gt;
  
  
  &amp;lt;/asp:Content&amp;gt;
  
  
  &lt;/pre&gt;
  </code></pre>
  
  <p>i wanna output like</p>
  
  <p><b>name---------------total_ leaves</b></p>
  
  <p>abc----------------  10</p>
  
  <p>xyz----------------  12</p>
  
  <p>pqr----------------  06</p>
  
  <p>So how can i do that?</p>
  
  <p>Thanks in advance...</p>