2016-12-01 156 views
-2

我想为图库做导航按钮。当我点击下一个时,它传递一个参数来指示需要执行哪个动作,例如下一个。相反,我得到一个404错误。这里是代码的细节:Url.Action路由不正确

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); 
    } 
} 

回答

7

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

+0

谢谢。我愚蠢的错误。 –

+0

一切都很好...完全人为的错误:) –