I have this Controller :
public class ProfileController : Controller
{
public ActionResult Index( long? userkey )
{
...
}
public ActionResult Index( string username )
{
...
}
}
how can i define MapRoute for this actions work like this:
mysite.com/Profile/8293378324043043840
this must be go to first action
mysite.com/Profile/MyUserName
this must be go to second action
I have this route for the first action
routes.MapRoute( name: "Profile" , url: "Profile/{userkey}" , defaults: new { controller = "Profile" , action = "Index" } );
do i need add another MapRoute ? or can i change the current MapRoute for both action?
First you cannot overload controller actions if you are using the same Http Verb (in your case GET) because you need to have unique action names.
So you need to name your actions differently:
Or you can use the
ActionNameAttributeto give different names to your actions:Then you will need two routes with using route constraints on the
userkeyto be a numeric value to setup your actions: