I have controller with 2 methods, with following signature:
public class TestController
{
[HttpGet]
public ActionResult TestMethod1()
{
//here code
return Json(1, JsonRequestBehavior.AllowGet);
}
[HttpGet]
public ActionResult TestMethod2(long userId)
{
//here code
return Json("userId= " + userId, JsonRequestBehavior.AllowGet);
}
}
I want to create the following routers for this methods:
For the first method:
http://domain/test/
For the second method:
http://domain/test?userId={userId_value}
I tried to use the following routes:
1.
context.MapRoute("route_with_value",
"test/{userId}",
new { controller = "test", action = "TestMethod2" });
context.MapRoute("route_no_value",
"test",
new { controller = "test", action = "TestMethod1" });
but this way does not work for me
2.
context.MapRoute("route_with_value",
"test?userId={userId}",
new { controller = "test", action = "TestMethod2" });
context.MapRoute("route_no_value",
"test",
new { controller = "test", action = "TestMethod1" });
but I get the error:
The route URL cannot start with a '/' or '~' character and it cannot contain a '?' character.
Is it possible to create map route for my urls?