ArticleDirectory
Asp.net Dynamic Data Web Site 2 create the first web site
This topic describes the layout of an ASP. NET Dynamic Data website, including the creation of related folders and files by default.
Create a dynamic data website environment
Vs.net 2008 + SP1
Dynamic Data wizard 080608 (http://www.codeplex.com/aspnet)
Provides a wizard to create a dynamic data web site
Knowledge point:
LINQ-TO-SQL, ado.net framework entity.
System. Web. Routing
- Use a dynamic data website template to create a project dynamic data entities web site (provided by the ado.net Entity Framework data source) and dynamic data web site (the data source is provided by LINQ-to-SQL)
Chart 1
- The website layout created by using dynamic data is the user control generated by these templates, including webpage templates, field templates, content (CSS, images, JS, etc ).
Chart 2
Chart 3
Folders and files
The following table describes the files and folders created in the root directory of ASP. NET Dynamic Data Network.
files and folders |
description |
dynamicdata |
displays and operates data on pages, custom controls, pages, and child controls such as field controls |
default. aspx |
A default homepage displays all registered data models and table names. A hyperlink is used to display the content of the selected table. |
global. asax |
contains a method for registering the metadata model of a database instance, and add a routecollection object |
site.css |
display style of sites and controls |
site. master |
site template |
Web. config |
Configuration file to load necessary Class Libraries |
Web. config
Chart 4
- Add a metadatabase instance model (LINQ-TO-SQL)
Chart 5
- Register this metadata model and open global. asax
Public Static VoidRegisterroutes (RoutecollectionRoutes ){
MetamodelModel =New Metamodel();
// Model. registercontext (typeof (yourdatacontexttype), new contextconfiguration () {scaffoldalltables = false });
Routes. Add (New Dynamicdataroute("{Table}/{action}. aspx"){
Constraints =New Routevaluedictionary(New{Action ="List | details | edit | Insert"}),
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
//});
}
The createdLINQ-TO-SQLRegisterMetamodelMedium
Model. registercontext (Typeof(Norhwinddbdatacontext),New Contextconfiguration() {Scaffoldalltables =True});
- TestAfter compilation, F5, a website is created
Chart 6
HomepageCodeSegment to display all registered tables
Protected VoidPage_load (ObjectSender,EventargsE)
{
System. Collections.IlistVisibletables =Metamodel. Default. visibletables;
If(Visibletables. Count = 0)
{
Throw New Invalidoperationexception("There are no accessible tables. Make sure that at least one data model is registered in global. asax and scaffolding is enabled or implement custom pages .");
}
Menu1.datasource = visibletables;
Menu1.databind ();
}
Chart 7
The hyperlinks on each page areRoutecollection(System. Web. Routing)To redirect between pages and add/modify/delete data.; AboutSystem. Web. RoutingDetailed introduction to Asp.net MVC
Routes. Add (New Dynamicdataroute("{Table}/{action}. aspx"){
Constraints =New Routevaluedictionary(New{Action ="List | details | edit | Insert"}),
Model = Model
});
Next, we will explain how to use the routing rule to control table modification and add an operation page;