Home > DeveloperSection > Forums > How to use WebGrid in mvc
Ankit Singh

Total Post:341

Points:2389
Posted on    December-25-2015 9:36 PM

 .NET C#  .NET  Mvc  Mvc3  Mvc2  Mvc4  Mvc5 
Ratings:


 1 Reply(s)
 239  View(s)
Rate this:
I want to use WebGrid in mvc how to do this please help me.



aditya kumar Patel

Total Post:246

Points:1752
Posted on    December-25-2015 9:42 PM

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);
        }
    }
}


Modified On Dec-25-2015 09:46:24 PM

Don't want to miss updates? Please click the below button!

Follow MindStick