![]() ![]() ![]() You can specify a number of options in the WebGrid constructor and the GetHtml method in order to customize this behavior. The grid limits the amount of data displayed and includes pager links to move through the data column headings are rendered as links to enable paging. ![]() This small amount of code provides rich grid functionality. Finally, I use to generate the HTML for the grid and render it into the response. In the constructor I also set the defaultSort parameter to “Name” so theWebGrid knows that the data passed to it is already sorted by Name. Inside the div element I then instantiate a WebGrid, passing in the model data I do this inside an code block so that Razor knows not to try to render the result. The first line of the view specifies the model type (for example, the type of the Model property that we access in the view) to be IEnumerable. The List view includes the following Razor code, which renders the grid shown in Figure 1: = "Basic Web Grid" īasic Web grid = new WebGrid(Model, to zoom) My ProductController class has the following action: public ActionResult List() I’m using the Razor view engine for most of this article, but later I’ll also discuss how the WebForms view engine can be used. To show a simple example of WebGrid, I’ve set up an ASP.NET MVC action that simply passes an IEnumerable to the view. If you’re interested in the data-access code, it’s available in the code download, and you might also want to check out Julie Lerman’s article, “Server-Side Paging with the Entity Framework and ASP.NET MVC 3,” in the March 2011 issue ( /magazine/gg650669). The working samples build on top of a service that provides access to the AdventureWorksLT database via the Entity Framework. I’ll be focusing on WebGrid from an ASP.NET MVC aspect: creating a strongly typed version of WebGrid with full IntelliSense, hooking into the WebGrid support for server-side paging and adding AJAX functionality that degrades gracefully when scripting is disabled. This article looks at how to fit the WebGrid component into an ASP.NET MVC environment to enable you to be productive when rendering tabular data. (For an overview of WebMatrix-and the Razor syntax that will be used in this article-see Clark Sell’s article, “Introduction to WebMatrix,” in the April 2011 issue at /magazine/gg983489). In this article, I’ll introduce WebGrid and show how it can be used in ASP.NET MVC 3, then take a look at how to really get the most out of it in an ASP.NET MVC solution. One of these helpers, WebGrid, lets you render tabular data in a very simple manner with support for custom formatting of columns, paging, sorting and asynchronous updates via AJAX. The WebMatrix release included a number of productivity helpers to simplify tasks such as rendering charts and tabular data. Volume 26 Number 07 ASP.NET WebGrid - Get the Most out of WebGrid in ASP.NET MVCĮarlier this year Microsoft released ASP.NET MVC version 3 ( asp.net/mvc), as well as a new product called WebMatrix ( asp.net/webmatrix). ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |