Share via


ASP.NET Dynamic Data Infrastructure

This topic describes the layout of ASP.NET Dynamic Data applications and includes information about the folders and files that are created by default when using the Dynamic Data scaffolding.

You can create ASP.NET Dynamic Data Web applications in Visual Studio by using the ASP.NET Dynamic Data project templates. These templates generate the user controls, templates, and ASP.NET Web files that Dynamic Data uses to create UI for working with data.

Data Context Class

A Dynamic Data Web application requires a MetaModel object and a registered data context. The data context can be a LINQ-to-SQL class (an instance of the System.Data.Linq.DataContext class) or an ADO.NET Entity Framework class. The data context class should be in the application's App_Code folder. For more information, see ASP.NET Dynamic Data Layer Customization.

Folders and Files

The following table describes the files and folders that are created at the root level in an ASP.NET Dynamic Data Web site.

File or Folder

Description

Dynamic Data

Contains folders for custom controls and for pages that display data. For more information about the subfolders of the Dynamic Data folder, see DynamicData Folder Structure later in this topic.

Default.aspx

An ASP.NET page that displays the tables and views that are registered in the MetaModel instance. Each table name is rendered as a HyperLink control that displays the contents of the selected table.

Global.asax

Contains a method to register an instance of the MetaModel class and to add routes to the RouteCollection object.

Site.css

A cascading style sheet that is used by Dynamic Data page templates and controls.

Site.master

The master page for the site. Default.aspx and Dynamic Data page templates use the master page.

Global.asax File

In a Dynamic Data Web site, the Global.asax file contains a handler for the Application_Start event that is raised when the Web application starts. In the handler, the RegisterRoutes method is called. The RegisterRoutes method contains a MetaModel instance and a commented-out call to the MetaModel.RegisterContext method. To enable Dynamic Data operations, you must enable the RegisterContext method and pass to it a valid data context, such as a DataContext instance or ADO.NET Entity Framework context.

By default, the Global.asax file in a Dynamic Data Web site calls the Add method of the RouteCollection class to add routing for the List.aspx, Details.aspx, Edit.aspx, and Insert.aspx page templates for each action.

You can change the routing to the page templates by adding and removing route definitions in the Global.asax file. (Predefined alternative routes are included in the Global.asax file but are commented out.) For more information, see the comments in the Global.asax file. For information about page templates, see ASP.NET Dynamic Data Scaffolding.

To make all the database tables viewable by using Dynamic Data, you set the ScaffoldAllTables property of the ContextConfiguration object to true. Alternatively, you can set the ScaffoldTableAttribute attribute to true in the partial class that represents the table to be displayed. The ScaffoldTableAttribute attribute lets you selectively display tables by using Dynamic Data. For an example of how to do this, see the ScaffoldTableAttribute class overview.

Site.master File

The Site.master file is the master page for the Dynamic Data Web site. It is used by all Dynamic Data page templates. The Site.master file contains a System.Web.UI.ScriptManager control whose EnablePartialRendering property is set to true. For more information, see ASP.NET Master Pages.

Note

When the EnablePartialRendering property is set to true, exceptions that are thrown by the database server result in a run-time error in the browser. For example, if you try to update a row that has a column constraint that is defined in the database, and the update data violates the constraint, the browser will display a run-time error. When the EnablePartialRendering property is set to false, the browser does not display a detailed exception message. Instead, the browser displays an HTTP 500 error that indicates that a problem has occurred during server processing.

DynamicData Folder Structure

The following table describes the subfolders in the DynamicData folder.

File or folder

Description

Content

By default, contains the Images folder and a user control (GridViewPager.ascx). The Images folder contains graphics files that are used as icons for the pager control.

CustomPages

Container folder for custom page templates. Custom page templates are used to override the page templates that are defined in DynamicData\PageTemplates. For example, if the data context contains a table named Products, you can create a DynamicData\CustomPages\Products folder and add .aspx pages in the new folder that are used to display Products data. An easy way to start is to copy the pages from the DynamicData\PageTemplates folder into the DynamicData\CustomPages\Products, and then to modify the templates. For more information about custom page templates, see How to: Customize the Layout of an Individual Table By Using a Custom Page Template.

PageTemplates

Contains for page templates that create the UI to view and edit data. For more information, see ASP.NET Dynamic Data Scaffolding.

EntityTemplates

Contains entity templates that create table UI to view and edit data. For more information, see ASP.NET Dynamic Data Scaffolding.

FieldTemplates

Contains user controls that create the UI to view and edit data fields. For more information, see ASP.NET Dynamic Data Scaffolding.

FilterTemplates

Contains user controls that create the UI to filter data rows. For more information, see ASP.NET Dynamic Data Scaffolding.

GridViewPager Control

The GridViewPager.ascx file is a user control that derives from WebControl. It is used to enhance paging when there is more than one page of data for a table. The GridViewPager.ascx user control is used in the List.aspx and ListDetails.aspx page templates.

See Also

Concepts

ASP.NET Dynamic Data

ASP.NET Dynamic Data Scaffolding

Customizing ASP.NET Dynamic Data

Other Resources

LINQ to SQL

ADO.NET Entity Framework