Databases Reference
In-Depth Information
ViewName Route Parameter
In the examples of URL routing discussed so far, the action parameter has always matched
the name of the page template configured to handle it, such as the Details.aspx page
template, which handled the Details page action, and the List.aspx page template, which
handled the List action. Having a page template implement a single action makes it
focused and easy to maintain. Compared to a traditional ASP.NET WebForms approach
(where a single page often tries to support all three item-level actions—Insert, Edit, and
Details), single-action page templates are usually simpler. However, you are not limited to
having one-to-one relationships between actions and page templates.
If this makes sense in your application, you can have a single page template handle multi-
ple actions. Visual Studio project templates for Dynamic Data web applications include an
example of such a page template called ListDetails.aspx . This template combines a
GridView control similar to the one in the List page template and a FormView control that
displays details of the row currently selected in the grid. This page template can be regis-
tered to handle both List and Details actions as shown in this example:
RouteTable.Routes.Add(new DynamicDataRoute(“{table}”)
{
Action = PageAction.List,
ViewName = “ListDetails”
});
RouteTable.Routes.Add(new DynamicDataRoute(“{table}”)
{
Action = PageAction.Details,
ViewName = “ListDetails”
});
It is actually the ViewName property of the DynamicDataRoute class that determines the
name of the page template that will be used to handle the request. If the ViewName was
not provided by the route definition, Dynamic Data will assume it to be the same as the
Action parameter. Separation of Action from ViewName allows Dynamic Data web applica-
tions to change implementation of page templates without breaking the navigation in
existing ASPX pages.
Page Template Lookup Rules
Figure 6.10 summarizes the algorithm Dynamic Data uses to find an appropriate page
template and handle an incoming web request. Most of the power and flexibility in this
process comes from the ASP.NET routing.
 
 
Search WWH ::




Custom Search