When combining asp.net Dynamic Data and MVC MetaModel.Visible contains tables with Scaffold==false

我的未来我决定 提交于 2019-12-08 00:39:24

问题


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 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 = "" }
    );


来源:https://stackoverflow.com/questions/3471254/when-combining-asp-net-dynamic-data-and-mvc-metamodel-visible-contains-tables-wi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!