How to use WebGrid in mvc

I want to use WebGrid in mvc how to do this please help me.

Last updated:12/25/2015 9:42:34 PM

1 Answers

Anonymous User
Anonymous User

WebGrid is most powerful tools to list records from database in web application. Like ASP.NET Web Forms GridView, DataList, ASP.NET MVC didn't had any built in data controls. WebGrid that does almost all work of ASP.NET Web Form GridView and it is simple enough too.

Index.cshtml

@model IList<ForumMVC.Employee>

@{
    ViewBag.Title = 'Index';
}
 @{ 
var grid = new WebGrid(Model);
}

<h1>Employee List </h1>
<div id='grid'>
@grid.GetHtml()
</div>

 

HomeController

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ForumMVC;
using System.Data.Entity;
namespace ForumMVC.Controllers
{
    public class HomeController : Controller
    {
        forumEntities db = new forumEntities();
        public ActionResult Index()
        {
            List<Employee> Emplst = db.Employee.ToList();
            return View(Emplst);
        }
    }
}

Answer