Yvonne Delport Yvonne Delport - 1 year ago 72
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:


public static void RegisterRoutes(RouteCollection routes)

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>


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();
gallery = Gallary.getPortfolioGallery();

return View(gallery);

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download