Sure, here are the steps on how to use WebGrid in MVC:
Add the Web Grid library to your ASP.NET project.
Create a view that will display the Web Grid.
In the view, use the Web Grid to display the data.
Bind the Web Grid to a model.
Here is an example of the code:
HTML
@{
// Get the data for the Web Grid
var data = GetData();
}
<html>
<head>
<title>Web Grid</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/aspnet-webgrid/4.0.5/webgrid.min.js"></script>
</head>
<body>
<h1>Web Grid</h1>
<div id="web-grid">
</div>
<script>
$(document).ready(function() {
// Create the Web Grid
var webGrid = $("#web-grid").webGrid({
dataSource: data
});
});
</script>
</body>
</html>
This code will add the Web Grid library to your ASP.NET project. The GetData function will get the data for the Web Grid. The
web-grid element will be used to create the Web Grid. The dataSource attribute of the
web-grid element will be bound to the data returned by the GetData function.
The web-grid element will be bound to the webGrid method of the
Web Grid library. The webGrid method will handle the events of the Web Grid.
Here are some of the features of WebGrid:
Paging: WebGrid can be paginated to display a limited number of records at a time.
Sorting: WebGrid can be sorted by any column.
Filtering: WebGrid can be filtered to display only the records that match the specified criteria.
Editing: WebGrid can be used to edit the data in the grid.
Deleting: WebGrid can be used to delete the data in the grid.
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); } } }
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
Sure, here are the steps on how to use WebGrid in MVC:
Here is an example of the code:
HTML
This code will add the Web Grid library to your ASP.NET project. The
GetDatafunction will get the data for the Web Grid. Theweb-gridelement will be used to create the Web Grid. ThedataSourceattribute of theweb-gridelement will be bound to the data returned by theGetDatafunction.The
web-gridelement will be bound to thewebGridmethod of theWeb Gridlibrary. ThewebGridmethod will handle the events of the Web Grid.Here are some of the features of WebGrid:
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