与url不同的操作名称

问题描述:

是否有可能使用与url中指定的操作名称不同的名称的操作方法?我试图用Global.asax中的路由表做这件事,但没有运气。以下是我尝试的:与url不同的操作名称

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

我想将操作方法​​称为ApproveSeller,但将网址设为ApproveSellers。

你需要使用action属性做到这一点。在路线中,您只需定义默认值值。

这里是控制器:

public class AccountController 

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

    ... 

有一个attribute for that

[ActionName("NewName")] 
    public ActionResult OldName() 
    { 
     return View(); 
    } 

下午好,您可能会想尝试一下使用ActionName Attrribute,菲尔哈克有一个很好的文章here,你可能想看一看。