Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Action name different to url

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.

like image 390
Sachin Kainth Avatar asked Jan 27 '12 17:01

Sachin Kainth


2 Answers

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
    {

    ...
like image 66
Aliostad Avatar answered Sep 20 '22 02:09

Aliostad


There is an attribute for that:

    [ActionName("NewName")]
    public ActionResult OldName()
    {
        return View();   
    }
like image 27
Henk Holterman Avatar answered Sep 18 '22 02:09

Henk Holterman