Home > DeveloperSection > Forums > How to Bind GridView in MVC4 with Database
Ankit Singh

Total Post:341

Points:2389
Posted on    November-24-2015 10:36 PM

 .NET C#  Mvc  Mvc3  Mvc2  Mvc4  Mvc5 
Ratings:


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


aditya kumar Patel

Total Post:244

Points:1736
Posted on    November-24-2015 10:40 PM

 

@model IEnumerable<ForumMVC.Employee> 
@{ 
    ViewBag.Title = "Bind Gridview with Database"; 
    WebGrid grid = new WebGrid(Model); 
}   
<h2>Bind GridView in MVC4 with Database</h2> 
@grid.GetHtml(columns: new[]   

    grid.Column("Emp_ID"), 
    grid.Column("Emp_Name"), 
    grid.Column("Emp_Sal")
}  
)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Threading.Tasks;
using System.Diagnostics;
using ForumMVC;
namespace ForumMVC.Controllers
{
    public class HomeController : Controller
    {
        forumEntities db = new forumEntities();
        public ActionResult Index()
        {
            IEnumerable<Employee> LIst = db.Employee.ToList();
            return View(LIst);
        }
        

    }
}


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

Follow MindStick