Url.Action无法正确路由

时间:2016-12-01 12:28:43

标签: c# asp.net-mvc

我正在尝试为图库创建导航按钮。当我单击下一步时,它传递一个参数以指示需要执行哪个操作,例如下一个。相反,我得到404错误。以下是代码详细信息:

RouteConfig.cs:

public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            name: "Default",
            url: "{controller}/{action}/{actionType}",
            defaults: new { controller = "Home", action = "Index", actionType = UrlParameter.Optional }
        );
    }

查看:

<div class="post-navi">
                <a class="prev" href="@Url.Action("Portfolio", "Gallery", new { actionType = "Prev" })">&lt;</a>
                <a class="next" href="@Url.Action("Portfolio", "Gallery", new { actionType = "Next" })">&gt;</a>
                <div class="clear"></div>
            </div>

控制器:

public class GallaryController : Controller
{
    //
    // GET: /Gallary/Portfolio/actionType
    public ActionResult Portfolio(string actionType)
    {
        List<Gallary> gallery = null;

        if (actionType == "Prev")
        {
            gallery = Gallary.getPortfolioPrev();
        }
        else if (actionType == "Next")
        {
            gallery = Gallary.getPortfolioNext();
        }
        else
        {
            gallery = Gallary.getPortfolioGallery();
        }

        return View(gallery);
    }
}

1 个答案:

答案 0 :(得分:7)

将Gallary更改为图库... 错误的控制器名称......