Dynamic Data Web Application


Today, in this article let's play around with one of the interesting and most useful concepts in C#.

Question: What is dynamic data web application?

In simple terms "It enables performing the CRUD operations with the help of pre-defined created dynamic templates".

Step 1: Create a new webform project:


Step 2: Add a new ADO.NET Data Entity Model item:

ADO.NET Data Entity Model.png



Step 3: The output of Global.asax.cs looks like this:

using System;
using System.ComponentModel.DataAnnotations;
using System.Web;
using System.Web.DynamicData;
using System.Web.Routing;
    public class Global : System.Web.
        private static MetaModel s_defaultModel = new MetaModel();
        public static MetaModel DefaultModel
            get{return s_defaultModel;
        public static void RegisterRoutes(RouteCollection routes)
// 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(CompanyEntities), new ContextConfiguration()
            { ScaffoldAllTables = true });
// 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});
        void Application_Start(object sender, EventArgs e)

Step 4: The output of the application looks like this:



Step 5: The data inserted output of the application looks like this:





I hope this article is useful for you. I look forward for your comments and feedback. Thanks Vijay Prativadi

Up Next
    Ebook Download
    View all
    View all
    MVC Corporation is consulting and IT services based company.