locked
Getting routes which are not registered in action constraints RRS feed

  • Question

  • User-567247610 posted

    Hi, I'm using SP1 version of dynamic data. My current issue is that if one table is set to be scaffolded, routes for all 4 actions (List, Details, Edit, Insert) are generated for that table, no matter if they are set in global.asax or not.

    To be more clear, here is the code in Global.asax:

     

    1                baseTablesModel.RegisterContext(typeof(LinqToSql.BaseTablesDataContext), new ContextConfiguration()
    2                {
    3                    ScaffoldAllTables = false,
    4                    MetadataProviderFactory = (type => new InMemoryMetadataTypeDescriptionProvider(type, new AssociatedMetadataTypeTypeDescriptionProvider(type)))
    5                });
    6    
    7                // Add common routes for all tables
    8                routes.Add(new DynamicDataRoute("Modules/{table}/{action}.aspx")
    9                {
    10                   Constraints = new RouteValueDictionary(new { action = "List|Details" }),
    11                   Model = baseTablesModel
    12               });
    13   
    14               // Tables with List, Details , Insert Action
    15               System.Collections.Generic.List<string> tablesWithInsertAction = new System.Collections.Generic.List<string>();
    16               tablesWithInsertAction.Add("aspnet_Roles");
    17   
    18               // Tables with just List, Details Action
    19               System.Collections.Generic.List<string> tablesReadOnly = new System.Collections.Generic.List<string>();
    20               tablesReadOnly.Add("aspnet_Memberships");
    21   
    22               foreach (MetaTable table in baseTablesModel.Tables)
    23               {
    24                   if (tablesWithInsertAction.Contains(table.Name))
    25                   {
    26                       routes.Add(new DynamicDataRoute("Modules/{table}/{action}.aspx")
    27                       {
    28                           Model = baseTablesModel,
    29                           Table = table.Name,
    30                           Action = PageAction.Insert 
    31                       });
    32                   }
    33                   else if (!tablesReadOnly.Contains(table.Name))
    34                   {
    35                       routes.Add(new DynamicDataRoute("Modules/{table}/{action}.aspx")
    36                       {
    37                           Model = baseTablesModel,
    38                           Table = table.Name,
    39                           Constraints = new RouteValueDictionary(new { action = "Insert|Edit" }),
    40                       });
    41                   }
    42               }
    43   
    44   
    
       

    With this code, if I'm not wrong,

    aspnet_Roles table should have List,Details and Insert.aspx;
    aspnet_Membership(s) table should have just List and Details.aspx

    However, they both have pages for all 4 actions. Is routes configured elsewhere in this version or am I missing something?

    Friday, August 29, 2008 4:43 PM

All replies

  • User1641955678 posted

    I think your Insert route is incorrect, because it will match all incoming actions without contraints.  To fix it, please add a constraint, or more simply do this:

        routes.Add(new DynamicDataRoute("Modules/{table}/Insert.aspx") 

    David

    Friday, August 29, 2008 9:17 PM