Asp.net Dynamic Data Web Site 2 create the first web site

Source: Internet
Author: User
ArticleDirectory
    • Environment
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

 

 

    1. 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

 

    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

 

    1. Add a metadatabase instance model (LINQ-TO-SQL)

Chart 5

    1. 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});

 

    1. 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;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.