I have 3 actions in a controller. I would like the first two to be /posts/new, and the last to be /posts/{filter}?page=N
//all are in the PostsController
[HttpGet]
public ActionResult New()
[HttpPost]
public ActionResult New(PostView post)
[HttpGet]
public ActionResult Browse(string filter, int page)
The routes I have defined now are:
routes.MapRoute("BrowsePosts",
"posts/{filter}",
new { controller = "posts", action = "browse", filter = "", page = 1 },
new { controller = "posts", action = "browse", page = @"\d+" });
routes.MapRoute("NewPost",
"posts/new",
new { controller = "", action = "" },
new { controller = "posts", action = "new" });
I thought the constraints I put on them would do the trick, but the requests are all being sent through the first route. What am I doing wrong?
Your “NewPost” route needs to be first, as that route would be matched by your “BrowsePosts” route.
Routes are analyzed in order and at the first match that is the route that is utilized.
Map your “NewPost” route first and it should be fixed.