views:

42

answers:

2

I combined MVC and DD by creating a new DD project and adding the MVC stuff (references, routing, usings, etc).

The list of tables on default.aspx (from DD) will show all tables, including the ones with [ScaffoldTable(false)]. The URL's of the tables with Scaffold==true have the expected form (DD/TableName/List.aspx). However, the URL's of the tables that should not be shown are in the form /Home/List?Table=TableName.

If you leave out the MVC routing (Routes.MapRoute) then the tables with Scaffold(false) are not shown. Or you can leave out only the Parameter defaults.

My guess is that Dynamic Data determines if a table is visible by checking to see if a route can be made to for the List page. The DynamicDataRoute will not match because that will not generate a route if Scaffold==false. BUT THEN the MVC Route WILL match because of the Parameter defaults at the end.

Am I correct and is this a bug or am I completely missing something here?

EDIT: I fixed it by adding filtering the VisibleTables on Scaffold like this, but that's a workaround...

System.Collections.IList visibleTables = 
   MvcApplication.DefaultModel.VisibleTables.Where(o=>o.Scaffold==true).ToList();

My RegisterRoutes in global.asax.cs:

    public static void RegisterRoutes(RouteCollection routes)
    {
        DefaultModel.RegisterContext(typeof(studiebase2Entities), new ContextConfiguration() { ScaffoldAllTables = false });

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.Add(new DynamicDataRoute("DD/{table}/{action}.aspx")
        {
            Constraints = new RouteValueDictionary(new { action = "List|Details|Edit|Insert" }),
            Model = DefaultModel
        });

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
        );

    }
+1  A: 

A somewhat cleaner fix would be to add a constraint to your MVC route so that it doesn't match when a 'Table' is specified. e.g. something like:

    routes.MapRoute(
        "Default", // Route name
        "{controller}/{action}/{id}", // URL with parameters
        new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        new { Table = "" }
    );
David Ebbo
This works as a better workaround than I had. Scott Hanselman's team confirmed this as a bug so maybe it'll be fixed in a future version.
John Landheer