
Get Total numbers for row count, for example this example let's say it is 100 Model = context.ExampleUsageOfSQLServerPagingFeature(pageNumber, CountToShowPerPage).ToList() Using (var context = new AdventureWorks2012Entities1())
#Adventureworks2012 person type code
In your controller, code can be as below public ActionResult ListToShow(int? page) Now, Suppose you are using Entity framework(database first approach in my example) This is quite basics to call stored procedures using controller C#, if you want to directly call the SP, I have already mentioned it in the above answer you can use the this query EXECUTE ExampleUsageOfSQLServerPagingFeature 2, 10
#Adventureworks2012 person type how to
Simply execute the above created stored procedure by passing page number and row count to show /* Display Records Between 11 AND 20 BusinessEntityID */ĮXECUTE ExampleUsageOfSQLServerPagingFeature 2, 10įor showing this in view, you can just call the stored procedure and get the list of next 10 rows based on page number and show data in viewįor more details on how to implement paging in MVC View.

OBJECT_ID(N'.') AND type in (N'P', N'PC'))ĭROP PROCEDURE. IF EXISTS (SELECT * FROM sys.objects WHERE object_id = You can create the Stored procedure to use the same above query, here is the stored procedure query code for same USE AdventureWorks2012 You can do this again and again to fetch next 10 rows and so on. Now, if we want to get next page (next 10 rows), you can give OffSet value=10 to start fetching rows from 11th and useįetch Next 10 to get another 10 rows, here is the query. ,FirstName + ' ' + MiddleName + ' ' + LastName To fetch rows in Sql server(10/5 rows at a time) to apply pagination you can use OFFSET and FETCH (For SQL server 2012 and above), here is the example, I am using AdventureWorks2012 Databaseįetch First 10 rows of Table Person USE AdventureWorks2012
