6

Is it possible to have a action method with a name that is different to the action name specified in the url? I tried doing this with the routes table in Global.asax with no luck. Here's what I tried:

routes.MapRoute(
               "ApproveSellers",
               "Admin/Account/ApproveSellers/",
               new { controller = "Account", action = "ApproveSeller"},
               new[] { "UI.Areas.Admin.Controllers" }
            );

I want the action method to be called ApproveSeller but the url to be ApproveSellers.

JohnFx
  • 34,542
  • 18
  • 104
  • 162
Sachin Kainth
  • 45,256
  • 81
  • 201
  • 304

3 Answers3

5

You need to do it using action attribute. In the route, you just define the default value.

Here is in the controller:

public class AccountController

    [ActionName("ApproveSellers")]
    public ActionResult ApproveSeller
    {

    ...
Aliostad
  • 80,612
  • 21
  • 160
  • 208
2

There is an attribute for that:

    [ActionName("NewName")]
    public ActionResult OldName()
    {
        return View();   
    }
Community
  • 1
  • 1
H H
  • 263,252
  • 30
  • 330
  • 514
1

Good afternoon, you may want to try and look at using the ActionName Attrribute, Phil Haack has a good article here that you may want to take a look at.

mreyeros
  • 4,359
  • 20
  • 24