ASP.NET MVC 3中是否有ActionNameAttribute用于类类型声明?

Her*_*des 7 c# asp.net routing asp.net-mvc-3

无法想象这个问题还没有被问到......虽然,我找不到它.

所以这就是:我在ASP.NET MVC 3中的动作方法上使用了ActionNameAttribute.像这样:

[ActionName("confirm")]
[HttpGet]
public ActionResult Confirm(string stuffTitle)
{
   ActionResult resultView = CreateSomeStuff(stuffTitle);
   return resultView;
}
Run Code Online (Sandbox Code Playgroud)

但是,我怎样才能为课程做同样的事情呢?像这样:

[ActionName("personal")]
public class AccountController : Controller
Run Code Online (Sandbox Code Playgroud)

使用ActionNameAttribute,它只能在方法声明中使用.但我想它应该在类类型声明上以某种方式可行.也许我还没有听说过另一个属性?其他一些解决方法?

有人有想法吗?提前致谢!!

Dar*_*rov 6

我真的很难理解你追求的是什么.您想更改控制器的名称或其他内容吗?如果是这样,请使用路线:

routes.MapRoute(
    "FooRoute",
    "foo/{action}/{action}/{id}",
    new { controller = "Account", action = "Index", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)

现在所有请求foo/someaction都将路由到Account控制器的相应操作.