0

Before I ask a question I should say that; All routes have been added to the controllers by Route attribute. It's not a duplicate of this or this. Because ID parameter (integer type) is passed to the two different functions in this case.

There are two classes and two functions that all seperated in different class. HomeController.AppPage and BlogController.Detail functions conflicts when this page localhost:11111/Blog/this-is-blog-title/1 is navigated. I want to run Second One as I stated below.

In the Second One, Blog segment must be stable in the beginning of the route. I don't want to change or remove.

Thank you for your suggestion and help.

First One

public class HomeController : BaseController
    [Route("{title}/{ID}")]              //  -> No problem with this
    [Route("{title1}/{title2}/{ID}")]    //  -> Conflicting attribute
    public ActionResult AppPage(int ID)
    {
        // Some Code
        return View();
    }
}

Second One

public class BlogController : BaseController
    [Route("Blog/{title}/{ID}")]              //  -> Conflicting attribute
    public ActionResult Detail(int ID)
    {
        // Some Code
        return View();
    }
}
Fatih TAN
  • 778
  • 1
  • 5
  • 23

1 Answers1

0

try adding order parameter to the route attribute so that the Blog route takes precedence over the title1 route

By default, all defined routes have an Order value of 0 and routes are processed from lowest to highest

public class HomeController : BaseController
    [Route("{title}/{ID}")]              //  -> No problem with this
    [Route("{title1}/{title2}/{ID}", Order = 2)]    
    public ActionResult AppPage(int ID)
    {
        // Some Code
        return View();
    }
}

public class BlogController : BaseController
    [Route("Blog/{title}/{ID}", Order = 1)]             
    public ActionResult Detail(int ID)
    {
        // Some Code
        return View();
    }
}

if this did not work you can just list them in the RouteConfig.cs file and write the Blog route before the title1 route

you can read this article for more info

http://rion.io/2015/11/13/understanding-routing-precedence-in-asp-net-mvc/

a.tolba
  • 137
  • 1
  • 1
  • 13