Sure, here are the steps on how to use Web Grid shoring and paging 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.
Set the paging options for the Web Grid.
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,
pageSize: 10
});
});
</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
pageSize attribute of the web-grid element will set the number of records to be displayed per page.
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.
We can define WebGrid to display data on a web page using an HTML table element. It renders tabular data in a very simple manner with support for custom formatting of columns, paging, sorting.
The main properties inWebGridare:
Source– Where your data comes from. Usually the model passed by the controller action.
DefaultSort– Here you can define how the data will be sorted. Just provide the column name here.
RowsPerPage– Number of records that will be shown on table.
CanPage– Allows paging.
CanSort– Allows sorting by clicking on column title.
Index.cshtml
@model IList<ForumMVC.Employee>
@{ ViewBag.Title = "Index"; } @{ var grid = new WebGrid(Model, canPage: true, rowsPerPage: 5, selectionFieldName: "selectedRow",ajaxUpdateContainerId: "gridContent"); grid.Pager(WebGridPagerModes.NextPrevious);}
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 { forumEntitiesa db = new forumEntitiesa(); 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 Web Grid shoring and paging 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. ThepageSizeattribute of theweb-gridelement will set the number of records to be displayed per page.The
web-gridelement will be bound to thewebGridmethod of theWeb Gridlibrary. ThewebGridmethod will handle the events of the Web Grid.We can define WebGrid to display data on a web page using an HTML table element. It renders tabular data in a very simple manner with support for custom formatting of columns, paging, sorting.
The main properties in WebGrid are:
Index.cshtml