【问题标题】:ASP.NET MVC5 RoutePrefix controller nameASP.NET MVC5 RoutePrefix 控制器名称
【发布时间】:2014-07-22 15:19:08
【问题描述】:

我从 .NET MVC 框架开始。我正在使用 4.5 和 MVC5。

我有一个控制器“APropos”,在文件夹“APropos”等中有一个视图。效果很好!

但我希望我的网址看起来像“site.com/A-Propos”而不是“site.com/APropos”。

我在 Controller 中阅读了一些关于“RoutePrefix”的帖子:

[RoutePrefix("a-propos")]
public class AProposController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
}

我还将视图文件夹重命名为“a-propos”,但它不起作用...(找不到资源)

我相信有人知道解决方案!

感谢您的帮助:-)

【问题讨论】:

    标签: asp.net-mvc-5


    【解决方案1】:

    感谢您的帮助! 它适用于动作,但对于控制器,它不起作用。

    我指定了一个类似 msdn 的 RouteArea :

    [RouteArea("APropos", AreaPrefix = "A-Propos")]
    public class AProposController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    }
    

    网址始终是“monSite.com/apropos”而不是“monSite.com/a-propos”... 我必须做点别的吗?

    谢谢!

    编辑:

    我找到了解决办法!

    在 Route 属性上,我指定了这样的默认操作名称:

    [RoutePrefix("A-Propos")]
    [Route("{action=index}")]
    public class AProposController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    }
    

    感谢您的帮助。

    最好的问候

    【讨论】:

      猜你喜欢
      • 2015-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多