简体   繁体   English

如何使用实体框架在ASP MVC 3中为相关实体创建有意义的路由?

[英]How to create meaningful route in ASP MVC 3 with Entity Framework for related Entities?

Let's say I have two entities: 假设我有两个实体:

Company 1 -> * User 公司1-> *用户

If I want to go to the company 1, I use 如果我想去公司1,我用

http://localhost/Company/Details/1 http:// localhost / Company / Details / 1

What if I want to access the company Users? 如果我想访问公司用户该怎么办?

http://localhost/Company/Details/1/Users http:// localhost / Company / Details / 1 /用户

What if I want a pre-filled for adding users to this company? 如果我要预先填写将用户添加到该公司该怎么办?

http://localhost/Company/Details/1/Create http:// localhost / Company / Details / 1 /创建

How can I configure those routes and rewrite them to use the User controller, with the company parameter set? 如何设置公司参数,配置这些路由并重写以使用User控制器?

This is my best guess: 这是我最好的猜测:

  routes.MapRoute(
      "CompanyUsers",
      "Company/Details/{company_id}/{action}",
      new { controller = "User", id = company_id }
    );

Thanks 谢谢

Not 100% sure if this is what you're looking for but have you thought about utilizing Areas in your application? 不是100%不确定这是否是您要找的内容,但是您是否考虑过在应用程序中使用Areas This might give you the URL routing structure you're looking for. 这可能会为您提供所需的URL路由结构。

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

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