I wants to count the total leaves of each users from the database. and wants to display it in telerik gridview in Asp.Net MVC-3 (Aspx).
i 有两个栏的电网。 第1栏列出所有雇员/用户的名称,第2栏将显示这些用户的总休假。
页: 1 页: 1
leave_id (primary key) user_id (foreign key with user_id of table user_master) leave_days
user_master/b>
user_id (primary key) user_real_name
我的《示范公约》档案如下:
姓名:LeaveGridview.cs
<pre>
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; }
}
}
</pre>
第2次档案
姓名:LeaveGridviewFetch.cs
<pre>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace ProjectManagementSystem.Models
{
public class LeaveGridviewFetch
{
public static IList<LeaveGridview> all()
{
IList<LeaveGridview> result =
(IList<LeaveGridview>)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;
}
}
}
</pre>
My contgroller file name LeaveController.cs
<pre>
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()));
}
}
}
</pre>
我的看法
页: 1
<pre>
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
LeaveShow
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% Html.Telerik().Grid<ProjectManagementSystem.Models.LeaveGridview>()
.Name("grid")
.DataKeys(keys =>
{
keys.Add(l => l.leave_id);
})
.DataBinding(dataBinding =>
dataBinding.Ajax()
.Select("_SelectBatchEditing", "Leave") // Leave is controller name
)
.Columns(columns =>
{
columns.Bound(l => l.user_real_name).Width(200);
columns.Bound(l => l.leave_days).Width(150);
})
.Groupable()
.Pageable()
.Filterable()
.Render();
%>
</asp:Content>
</pre>
i 大麻产量
页: 1 10
页: 1 12
页: 1 页: 1
因此,如何做到这一点?
预告......