How to promote advanced ASP.NET MVC (3) routes (calculated actions, etc.)?

UPDATED

Given the following 8 routes, where Administrationis the area , the controller is, EmployeesControllerand Id is EmployeeId: p>

  • Administration/Corporate/{controller}/{Id}/Phones/{PhoneId}/Delete
    • action = DeletePhone
  • Administration/Corporate/{controller}/{Id}/Phones/{PhoneId}/Deactivate
    • action = DeactivatePhone
  • Administration/Corporate/{controller}/{Id}/Phones/{PhoneId}/Activate
    • action = ActivatePhone
  • Administration/Corporate/{controller}/{Id}/Notes/{NoteId}/Delete
    • action = DeleteNote
  • Administration/Corporate/{controller}/{Id}/Files/{FileId}/Delete
    • action = DeleteFile
  • Administration/Corporate/{controller}/{Id}/Addresses/{AddressId}/Delete
    • action = DeleteAddress
  • Administration/Corporate/{controller}/{Id}/Addresses/{AddressId}/Deactivate
    • action = DeactivateAddress
  • Administration/Corporate/{controller}/{Id}/Addresses/{AddressId}/Activate
    • action = ActivateAddress

How can I convert it to:

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

  • I need to take an object and split it (for which I already have code).
    • object = Phones( Phone)
  • Take an action and convert (rewrite?) It into an action + object (singularly).
    • action = Delete+ Phone( DeletePhone)

# 2, , - ?

, ? 8 , , 1. EmployeesController, CustomersController , 16 , 1. .

, , .

+3
2

.

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

ASP.NET MVC Subdomain Routing

+1

. , :

public static void RegisterRoutes()
{
    var adminRoutes = new[]
                            {
                                new [] { "Phones", "PhoneId", "Delete", "DeletePhone" },
                                // Add the rest of your routes here.
                            };

    foreach ( var adminRoute in adminRoutes )
    {
        RegisterAdminRoute( adminRoute[0], adminRoute[1], adminRoute[2], adminRoute[3] );
    }
}

public static void RegisterAdminRoute( string area, string idName, string actionName, string action )
{
    RouteTable.Routes.MapRoute
        (
            area + actionName,
            String.Format( "Administration/Corporate/{{controller}}/{{Id}}/{0}/{{{1}}}/{2}",
                            area,
                            idName,
                            actionName ),
            new { action }
        );
}
0

All Articles