博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

c# 扩展

Posted on 2019-04-22 21:08  火冰·瓶  阅读(119)  评论(0编辑  收藏  举报
public static string UrlName(this Type controller)
{
  var name = controller.Name;
  return name.EndsWith("Controller") ? name.Substring(0, name.Length - 10) : name;
}

  Then you can use:

Url.Action(nameof(ActionName), typeof(HomeController).UrlName())