在Grid上显示数据;在MVC中

时间:2014-01-18 05:23:26

标签: c# asp.net asp.net-mvc asp.net-mvc-3 view

我是MVC 3和Linq to Sql的新手,尝试在VIEW上显示我从数据库获取的数据。我通过表做但不喜欢它,我需要像Gridview(添加,删除,更新)等但找不到合适的方法。我试过Grid.MVC但找不到将它连接到我的代码的方法。有关我的代码的网格显示的任何方式吗?

控制器:

using EmployeeAttendance_app.Models;
namespace EmployeeAttendance_app.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            ViewBag.Message = "Precise Technology Consultants";
            var DataContext = new EmployeeAtdDataContext();
            var EmployeeAtd = DataContext.GetAttendance_Sp();
            return View(EmployeeAtd);
        }

查看:

<table>

 <tr>

      <th>
       Employer ID
      </th>
      <th>
       Employer Name
      </th>
      <th>
       Rec Date
      </th>
      <th>
       Rec Time
      </th>
      <th>
       Department Name
      </th>
 </tr>

 @foreach (GetAttendance_SpResult emp in (IEnumerable<GetAttendance_SpResult>)ViewData.Model) 
 {


     <tr>

      <td>@emp.EmplID</td>
      <td>@emp.EmplName</td>
      <td>@emp.RecDate</td>
      <td>@emp.RecTime</td>
      <td>@emp.DeptName</td>

     </tr>

 }
</table>

2 个答案:

答案 0 :(得分:0)

尚未尝试网格(已使用表格和for循环);但是,快速搜索出现了Grid.MVC.ajax   Grid.Mvc.Ajax extension grid initialization

如果(好的时候)我在周一尝试这个,我会按照上面引用的Grid.MVC.Ajax readmelink中提供的8个步骤...并更新此评论......

答案 1 :(得分:0)

我使用的两种方法详述如下。

第一个是jquery,datatables和mvc的混合体。

在代码项目中有一篇很好的文章:

http://www.codeproject.com/Articles/165410/ASP-NET-MVC-Editable-DataTable-jQuery-DataTables-a

第二个是使用kendo ui mvc helper grid:

http://docs.kendoui.com/getting-started/using-kendo-with/aspnet-mvc/helpers/grid/overview

第二个是支付部分费用。