このタスクを実行するためのカスタム属性を作成できます。
[AttributeUsage(AttributeTargets.Method, AllowMultiple=false, Inherited=true)]
public sealed class LocalizedActionNameAttribute : ActionNameSelectorAttribute
{
public LocalizedActionNameAttribute(string name, Type resourceType)
{
Name = name;
ResourceType = resourceType;
}
public Type ResourceType { get; private set; }
public string Name { get; private set; }
public override bool IsValidName(ControllerContext controllerContext, string actionName, System.Reflection.MethodInfo methodInfo)
{
var rm = new ResourceManager(ResourceType);
var name = rm.GetString(Name);
return string.Equals(actionName, name, StringComparison.OrdinalIgnoreCase);
}
}
その後:
[LocalizedActionName("Index", typeof(Resources.Resources))]
public ActionResult Index()
{
return View();
}