Reputation: 4862
I like to create register a route like these:
User/{^[a-zA-Z]+$}/{controller}/{action}/{id}
That's how the URL should look like :
/User/myUser/Product/Action
So i register a route in the AreaRegistration. The constraint should only allow words.
context.MapRoute(
"Customer_Default",
"User/{^[a-zA-Z]+$}/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
RedirectToAction
route?Upvotes: 0
Views: 73
Reputation: 506
Upvotes: 0
Reputation: 11971
You need to utilise the constraints
parameter of MapRoute()
context.MapRoute(
"Customer_Default",
"User/{username}/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional },
constraints: new { username= @"^[a-zA-Z]+$" }
);
Then your action would be like so:
public ActionResult ActionName(string username, int id)
Upvotes: 1