Databases Reference
In-Depth Information
Dynamic Data web applications rely on the general-purpose URL routing capabilities built
into ASP.NET. Routes are typically configured at the application start time, in the
Application_Start
event handler located in the
Global.asax
file.
RouteTable.Routes.Add(new DynamicDataRoute(
“{table}/{action}.aspx”
));
As discussed in the beginning of this chapter,
{table}
and
{action}
are placeholders for
the two route parameters that have special meaning in ASP.NET Dynamic Data. The first
parameter supplies the name of the table whose data needs to be displayed by a dynamic
page, and the second determines what kind of page needs to be displayed, or perhaps
more precisely,
how
the table data needs to be presented to the user. Dynamic Data
expects the table parameter to match the name of one of the
MetaTable
objects that
describe entity types registered in the global
MetaModel
, whereas the action parameter
provides the information necessary to find the appropriate page template to handle the
request. The route definition just shown allows Dynamic Data to determine that the
following page request URL applies to the table called Products and the page template
called List:
http://localhost/Products/List.aspx
Action Route Parameter
Routes do not have to include the action parameter as a part of the URL itself. Instead, it
can be specified by explicitly setting the
Action
property of the
DynamicDataRoute
class as
shown here:
RouteTable.Routes.Add(new DynamicDataRoute(“{table}”)
{
Action
= PageAction.List
});
Given this route definition, the URL for displaying a list of products will not include the
name of the page template at all and look like this instead:
http://localhost/Products
Table Route Parameter
Similarly, the table parameter does not have to come from the URL either; it can be speci-
fied using the
Table
property of the
DynamicDataRoute
class. Notice how in the following
example, the route definition does not include any parameters and simply hard-codes the
URL to
“Product”
(singular), which does not match the plural name of the table.