MVC routing does not work on lookup

in my Global.ascx.cs, I have this parameter for routing:

routes.MapRoute(
"HomeTarget",
"{TargetCode}",
new { controller = "Home", action = "Index", TargetCode = "" });

routes.MapRoute(
    "Default",                                              // Route name
    "{controller}/{action}/{id}",                           // URL with parameters
    new { controller = "Home", action = "Index", id = "" }  // Parameter defaults

In my HomeController, I have an Index () action like this:

[AcceptVerbs(HttpVerbs.Get)]
    public ActionResult Index(string TargetCode)
    {
        return View();
    }

When I go to a site, for example, mysite.com/Test1, I believe that it should accept “Test1” as a TargetCode, but it does not ... What should I do to load it “Test1” as a TargetCode, I don’t want do this: mysite.com/?TargetCode=Test1

Thanks a lot, Kenny.

0
source share
1 answer

Something seems to be acting on VS 2008 or with a framework. Now it works well. Thanks for watching.

0
source

Source: https://habr.com/ru/post/1720214/


All Articles