다음을 통해 공유


ASP.NET Dynamic Data Presentation Layer Customization

You can modify how Dynamic Data performs tasks that do not rely on a specific database schema. You can create these modifications one time and use them for any number of projects. This type of customization lets you define a consistent behavior for any schema without having to redefine the customization every time that you add or modify a data entity.

Note

For information about how to customize the data schema, see ASP.NET Dynamic Data Layer Customization.

This topic contains the following sections:

  • Page Templates

  • Entity Templates

  • Field Templates

  • Filter Templates

  • Page Routes

Page Templates

Dynamic Data lets you customize and extend the UI for rendering a table. You can modify the default field templates or create new ones in order to specify how tables are rendered.

Dynamic Data lets you customize page templates in the following ways:

  • Customize the layout for all tables. To do this, you change the page templates that are in the DynamicData\PageTemplates folder. You use this approach to change the appearance and behavior of all the tables in a Web site independently from the database. For more information, see How to: Customize ASP.NET Dynamic Data Default Field Templates.

  • Customize the layout for an individual table. To do this, you create a folder under the DynamicData\CustomPages whose name matches the name of the table in the data model. In the new folder, you add a page whose name matches the name of the default page template that you want to customize. You use this approach to change the appearance and behavior of an individual table for a specific database. For more information, see How to: Customize the Layout of an Individual Table By Using a Custom Page Template.

Entity Templates

Entity templates are user controls that let you customize the layout for a whole data row in a table. This provides more flexibility than customizing individual data fields, and is useful if you want to create custom UI and apply it to default or custom page templates. Dynamic Data lets you customize entity templates in the following ways:

  • Customize the layout for all tables. To do this, you customize the default entity templates. You perform this customization by changing the entity templates that are in the DynamicData\EntityTemplates folder. This customization gives you a more control than that provided by data field customization, and is useful if you want to apply a custom UI to default or custom page templates.

  • Customize the layout for an individual table. To do this, you create custom entity templates for the table whose layout you want to customize, which use the naming convention:

    • If you are using the LINQ to SQL data model to represent the AdventureWorksLT database, entity templates for the Address table would be named Addresses.ascx, Addresses_Edit.ascx and Addresses_Insert.ascx.

    • If you are using the ADO Entity Framework data model to represent the AdventureWorksLT database, entity templates for the Address table would be named Address.ascx, Address_Edit.ascx and Address_Insert.ascx.

These custom templates must be in the DynamicData\EntityTemplates folder. The following illustration shows an Address table row that has been customized by using a custom entity template.

Custom Entity Template Layout

For more information, see Walkthrough: Customizing Table Layout Using Entity Templates.

Field Templates

Field templates are ASP.NET user controls to which Dynamic Data maps data types in the data model. Dynamic Data lets you customize field templates in the following ways:

Filter Templates

Filter templates are user controls that render the UI for data filtering, which lets the user display the table rows based on a selected column value. Dynamic Data lets you customize filter templates in the following ways:

  • Customize the filter for a specific data type. To do this, you modify the controls in the DynamicData\FilterTemplates folder.

  • Create a custom filter. To do this, you create an ASP.NET user control that derives from the QueryableFilterUserControl class. You use this approach to override a default filter or to create a data type filter if a default one does not exist. A Visual Studio project with source code is available to accompany this topic: Scaffolding Dynamic Data.

For more information, see Walkthrough: Filtering Rows in Tables That Have a Parent-Child Relationship.

Page Routes

Dynamic Data uses ASP.NET routing to match and handle URL requests. The routes are defined in the Global.asax file. By default, Dynamic Data uses a different page template for each request (list, select, edit, and insert). (The List and Details pages both include delete functionality, so no page template is provided specifically for delete operations.)

You can customize the default routes. You can also specify different page templates or pass parameters using routes instead of using query-string values. For more information about routes, see ASP.NET Routing.

Dynamic Data lets you customize routing in the following ways:

  • Use a single page template for all operations. You can customize the routes so that all Web requests (operations) go to one page. The following example shows a customized route that enables all operations in one page for a given table. The second route enables a page to navigate to the details of a record, such as navigating to a relationship table based on a foreign key.

    routes.Add(New DynamicDataRoute("{table}/ListDetails.aspx") With { _
      .Action = PageAction.List, _
      .ViewName = "ListDetails", _
      .Model = model})
    
    routes.Add(New DynamicDataRoute("{table}/ListDetails.aspx") With { _
      .Action = PageAction.Details, _
      .ViewName = "ListDetails", _
      .Model = model})
    
    routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
    {
        Action = PageAction.List,
        ViewName = "ListDetails",
        Model = model
    });
    
    routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx")
    {
        Action = PageAction.Details,
        ViewName = "ListDetails",
        Model = model
    });
    
  • Create a route for an individual table.

    Routes are processed in the order they are defined, so you must add routes in order from more specific to more general. The following example shows how to specify a different page template for the Products table of the AdventureWorks database.

    routes.Add(New DynamicDataRoute("Products/{action}.aspx") With { _
      .ViewName = "ListDetails", _
      .Table = "Products", _
      .Model = model})
    
    routes.Add(New DynamicDataRoute("{table}/{action}.aspx") With { _
      .Constraints = New RouteValueDictionary( _
        New With {.Action = "List|Details|Edit|Insert"}), _
      .Model = model})
    
    routes.Add(new DynamicDataRoute("Products/{action}.aspx")
    {
        ViewName = "ListDetails",
        Table = "Products",
        Model = model
    });
    
    routes.Add(new DynamicDataRoute("{table}/{action}.aspx")
    {
        Constraints = new RouteValueDictionary(
          new { action = "List|Details|Edit|Insert" }),
        Model = model
    });
    

Back to top

See Also

Tasks

Walkthrough: Adding Dynamic Data Scaffolding to Existing ASP.NET Web Sites

Concepts

ASP.NET Dynamic Data

ASP.NET Dynamic Data Scaffolding

ASP.NET Dynamic Data Layer Customization