Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do advanced ASP.NET MVC (3) routes (computed actions, etc.)?

UPDATED

Considering the following 8 routes where Administration is area, controller is EmployeesController and Id is EmployeeId:

  1. Administration/Corporate/{controller}/{Id}/Phones/{PhoneId}/Delete
    • action = DeletePhone
  2. Administration/Corporate/{controller}/{Id}/Phones/{PhoneId}/Deactivate
    • action = DeactivatePhone
  3. Administration/Corporate/{controller}/{Id}/Phones/{PhoneId}/Activate
    • action = ActivatePhone
  4. Administration/Corporate/{controller}/{Id}/Notes/{NoteId}/Delete
    • action = DeleteNote
  5. Administration/Corporate/{controller}/{Id}/Files/{FileId}/Delete
    • action = DeleteFile
  6. Administration/Corporate/{controller}/{Id}/Addresses/{AddressId}/Delete
    • action = DeleteAddress
  7. Administration/Corporate/{controller}/{Id}/Addresses/{AddressId}/Deactivate
    • action = DeactivateAddress
  8. Administration/Corporate/{controller}/{Id}/Addresses/{AddressId}/Activate
    • action = ActivateAddress

How can I transform it into:

Administration/Corporate/{controller}/{Id}/{object}/{ObjectId}/{action} where object is Phones|Notes|Files|Addresses|? and action is Delete|Deactivate|Activate|??

  1. I need to take object and singularize it (for which I already have the code).
    • object = Phones (Phone)
  2. Take action and transform (rewrite?) it into action + object (singularized).
    • action = Delete+Phone (DeletePhone)

I can do everything up to the second #2 where the issue is how can I transform the action into something else in the route definition?

Is any of this even possible at all? It would be nice to take the 8 routes I have now and turn them into 1. And this example only uses my EmployeesController, my CustomersController is twice that size so about 16 routes that can be turned into 1. It would save a lot of space and code.

Anyway, I'm looking forward to suggestions and ideas if this is possible.

like image 958
Gup3rSuR4c Avatar asked Dec 14 '25 14:12

Gup3rSuR4c


1 Answers

You can create custom route handler.

public class CustomRoute : RouteBase
{
    //your custom code
}

ASP.NET MVC Subdomain Routing

like image 152
Peyman Avatar answered Dec 17 '25 05:12

Peyman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!