HOW TO BIND GRIDVIEW IN MVC4 WITH DATABASE

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
C#  Mvc  Mvc3  Mvc2  Mvc4  Mvc5 
 1624  View(s)
Ratings:
Rate this:
I want to use GridView in mvc how to use please help me.
  1. aditya kumar Patel

    Post:254

    Points:1810
    Re: How to Bind GridView in MVC4 with Database

     

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

        }
    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!