Hello everyone :I am working on a .net mvc3 application.
Here is my controller and action :
public class Foo_Bar : Controller
{
public ViewResult Foo_Bar()
{
return View();
}
}
And my corespondent view file is : Foo_Bar.cshtml
now ,my question is : I have a url as: http://www.mystite.com/foo-bar/foo-bar
but this url can not invoke the Foo_Bar/Foo_Bar controller and action except I write it as thes: http://www.mystite.com/foo_bar/foo_bar .
Now I need to replace the “-” with “_” before the route system mapping my controller and action. Can I do it in the routes.MapRoute()? Some one please help me .Thank you advance !ps:this is my first time to ask an question in Stack overflow:)
You can create a custom
RouteHandlerto change the values for{action}and{controller}. First, create your RouteHandler, as follows:Then, change your Default route as follows:
When a request is satisfied by this route, the RouteHandler will change the dashes to underbars.