当结合 asp.net 动态数据和 MVC MetaModel.Visible 包含 Scaffold==false 的表时
我通过创建一个新的 DD 项目并添加 MVC 内容(引用、路由、使用等)来组合 MVC 和 DD。
default.aspx 上的表列表(来自 DD)将显示所有表,包括带有 [ScaffoldTable(false)] 的表。 Scaffold==true 的表的 URL 具有预期的形式 (DD/TableName/List.aspx)。但是,不应显示的表的 URL 格式为 /Home/List?Table=TableName。
如果省略 MVC 路由 (Routes.MapRoute),则不会显示具有 Scaffold(false) 的表。或者您可以仅省略参数默认值。
我的猜测是,动态数据通过检查是否可以为列表页面建立路由来确定表是否可见。 DynamicDataRoute 将不匹配,因为如果 Scaffold==false,则不会生成路由。但是,由于最后的参数默认值,MVC 路由将匹配。
我是否正确,这是一个错误还是我在这里完全遗漏了一些东西?
编辑: 我通过像这样在脚手架上添加过滤 VisibleTables 来修复它,但这是一个解决方法......
System.Collections.IList visibleTables =
MvcApplication.DefaultModel.VisibleTables.Where(o=>o.Scaffold==true).ToList();
我在 global.asax.cs 中的 RegisterRoutes:
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
);
}
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
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一个更干净的修复方法是添加 约束到您的 MVC 路由,以便在指定“表”时它不匹配。例如:
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: