Articles → .NET → Basic example of asp.net dynamic data

Basic example of asp.net dynamic data






Objective of this Tutorial





Prerequisites























Steps Involved

















Step 1: Create a new project of type ‘ASP.NET

Dynamic Entities Web Application’
















Picture showing selecting asp.net dynamic data project from project template

Click to Enlarge




Step 2: Create tables at the backend




Picture showing schema of class table

Click to Enlarge

Picture showing schema of section table

Click to Enlarge



Picture showing the data in class table

Click to Enlarge

Picture showing the data in section table

Click to Enlarge


Step3: Add a new entity data model










Picture showing selecting the ado.net entity data model

Click to Enlarge







Picture showing the selection of generate from database option

Click to Enlarge





Picture showing selection of data source

Click to Enlarge



Picture showing selection of database

Click to Enlarge



Picture showing the connection string of entity model

Click to Enlarge





Picture showing selection of class and section table for entity model

Click to Enlarge



Picture showing adding the entity model model1.edmx in solution explorer

Click to Enlarge


Step 4: Add code to the global.asax




public static void RegisterRoutes(RouteCollection routes) {
	DefaultModel.RegisterContext(typeof(DynamicDataEntities), new ContextConfiguration() {
		ScaffoldAllTables = true
	});
	//                    IMPORTANT: DATA MODEL REGISTRATION 
	// Uncomment this line to register an ADO.NET Entity Framework model for ASP.NET Dynamic Data.
	// Set ScaffoldAllTables = true only if you are sure that you want all tables in the
	// data model to support a scaffold (i.e. templates) view. To control scaffolding for
	// individual tables, create a partial class for the table and apply the
	// [ScaffoldTable(true)] attribute to the partial class.
	// Note: Make sure that you change "YourDataContextType" to the name of the data context
	// class in your application.
	//DefaultModel.RegisterContext(typeof(YourDataContextType), new ContextConfiguration() { ScaffoldAllTables = false });

	// The following statement supports separate-page mode, where the List, Detail, Insert, and 
	// Update tasks are performed by using separate pages. To enable this mode, uncomment the following 
	// route definition, and comment out the route definitions in the combined-page mode section that follows.
	routes.Add(new DynamicDataRoute("{table}/{action}.aspx") {
		Constraints = new RouteValueDictionary(new {
			action = "List|Details|Edit|Insert"
		}),
		Model = DefaultModel
	});

	// The following statements support combined-page mode, where the List, Detail, Insert, and
	// Update tasks are performed by using the same page. To enable this mode, uncomment the
	// following routes and comment out the route definition in the separate-page mode section above.
	//routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") {
	//    Action = PageAction.List,
	//    ViewName = "ListDetails",
	//    Model = DefaultModel
	//});

	//routes.Add(new DynamicDataRoute("{table}/ListDetails.aspx") {
	//    Action = PageAction.Details,
	//    ViewName = "ListDetails",
	//    Model = DefaultModel
	//});
}



Step 5: Run the application




Picture showing the output with class and section table names

Click to Enlarge



Picture showing the output of class table

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, March 13, 2014

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250