How to pass a string type for MapRoute?

332 Views Asked by At

Can you guys please check this MapRoute,

routes.MapRoute(
                "Topic", // Route name
                "{controller}/{action}/{letter}", // URL with parameters
                new { controller = "Topic", action = "Letter", letter = UrlParameter.Optional } // Parameter defaults
            );

I'm passing an object named "letter". This is a string. The problem that I encountered here is this, when I pass it using the .RouteLink() function

@Html.RouteLink(item, "Topic", new { controller = "Topic", action = "Letter", letter = "A" })

The result is null, for letter.

public ActionResult Letter(string letter)
{
return View();
}

Is there a way wherein I will pass a string type on the MapRoute ? Thanks.

1

There are 1 best solutions below

0
On

You can do like this

routes.MapRoute(
            "Topic",                                           // Route name
            "Topic/{entry}",                                  // URL with parameters
            new { controller = "Topic", action = "Letter" }  // Parameter defaults
        );