简体   繁体   中英

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

Then I've a section controller

ClassSection

so I would do

Class/1/ClassSection/ (Create, ... ) since ClassSection without classid is useless

and then further

Class/1/ClassSection/1/Instance

to go to SectionInstance controller

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

You should consider using Areas. It sounds like you're moving in this direction already, but ASP.NET MVC 2.0 has specific support for this.

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. Try removing that part of your MapRoute and see if that fixes the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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