Yvonne Delport Yvonne Delport - 3 days ago 5
C# Question

Url.Action not routing correctly

I am trying to make navigation buttons for an image gallery. When I click next it passes a parameter to indicate which action needs to be performed e.g. Next. Instead I get a 404 error. Here is the code details:

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


View:

<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>


Controller:

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

Answer

Change Gallary to Gallery... Wrong controller name...

Comments