简体   繁体   English

ASP.NET MVC主站详细信息和路由

[英]asp.net mvc master details and routing

I'm trying to model class and sections of a class and further instances of sections. 我正在尝试对类和类的某个部分以及其他部分进行建模。

so route should be Class/ (Create, Details, Index, Edit) for classes 所以路由应该是Class /(创建,详细信息,索引,编辑)

Then I've a section controller 然后我有一个分区控制器

ClassSection ClassSection

so I would do 所以我会做

Class/1/ClassSection/ (Create, ... ) since ClassSection without classid is useless Class / 1 / ClassSection /(Create,...),因为没有classid的ClassSection是无用的

and then further 然后进一步

Class/1/ClassSection/1/Instance 类/ 1 / ClassSection / 1 /实例

to go to SectionInstance controller 去SectionInstance控制器

how can I map my routes to conform to this notation 如何映射我的路线以符合此表示法

I've tried doing this for class sections 我已经尝试过在课堂上这样做

  routes.MapRoute(
      "ClassSections",
      "Class/{classid}/ClassSection/{action}/{id}",
      new { controller = "ClassSection" },
      new { classid = @"d+" }
  );

but I can't generate a proper link from Html.ActionLink in Index action of Class 但我无法从Html.ActionLink在类的Index操作中生成正确的链接

You should consider using Areas. 您应该考虑使用Areas。 It sounds like you're moving in this direction already, but ASP.NET MVC 2.0 has specific support for this. 听起来您已经朝这个方向发展,但是ASP.NET MVC 2.0已对此提供了特定的支持。

http://haacked.com/archive/2009/07/31/single-project-areas.aspx http://haacked.com/archive/2009/07/31/single-project-areas.aspx

Given the hard constrains "Class" and "ClassSection" in your Url template, I doubt that you need new { classid = @"d+" } to make it a unique match. 考虑到Url模板中的“ Class”和“ ClassSection”有严格的约束,我怀疑您是否需要新的{classid = @“ d +”}使其唯一匹配。 Try removing that part of your MapRoute and see if that fixes the problem. 尝试删除MapRoute的那一部分,看看是否可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM