【问题标题】:asp mvc route behaviorasp mvc 路由行为
【发布时间】:2013-07-12 20:48:17
【问题描述】:

我的 asp mvc 应用程序中的例程有问题:The resource cannot be found.

Requested URL: /Admin/Users/Update

我的操作代码是:

[HttpGet]
public ActionResult UpdateUser(int userId)
{
    -some code-
    return View();
}

ActionLink 是:

@Html.ActionLink((string)fullName, "Update", "Users", new { userId = user.Id }, null)

路线:

public override void RegisterArea(AreaRegistrationContext context)
{
    context.MapRoute(
        "Admin_default",
        "Admin/{controller}/{action}/",
        new { controller = "Units", action = "Units" },
        new [] {"RSystem.Areas.Admin.Controllers"}
     );
 }

但其他动作,例如

public ActionResult Users(Role? role)

工作正常

【问题讨论】:

    标签: asp.net-mvc asp.net-mvc-4 routing


    【解决方案1】:

    更改您的 ActionLink 以匹配操作名称:

    @Html.ActionLink((string)fullName, "UpdateUser", "Users", new { userId = user.Id }, null)
    

    【讨论】:

      【解决方案2】:

      从 nuget 安装 T4MVC 并避免这些错误,您的智能中将拥有控制器和动作! 我知道硬编码控制器和动作名称是一件令人头疼的事情。

      您的 t4mvc 代码:

      @Html.ActionLink((string)fullName, MVC.Users.UpdateUser(), new { userId = user.Id }, null);
      

      试一试。

      【讨论】:

        【解决方案3】:

        由于您的 ActionResult 方法名称是 UpdateUser,所以在 ActionLink 中您必须像这样传递

        @Html.ActionLink((string)fullName, "UpdateUser", "Users", new { userId = user.Id }, null)
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-11-01
          • 2010-12-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多