Reputation: 43
I have a very simple MVC application:
When I type:
http://locahost:8080
the following route in the routeconfig takes me to the Home controller:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
When I type the following, I get 404 error.
http://locahost:8080/JohnDoe
I want to map this request to Home Controller's Get Action with name function (see below). How do I go about doing that?
public Person Get(string name)
{
PersonRespository db = new PersonRespository();
return db.GetPerson(name);
}
Thanks a lot guys.
Upvotes: 1
Views: 63
Reputation: 19241
Following should work.
routes.MapRoute(
name: "Custom",
url: "{name}",
defaults: new
{
controller = "Home",
action = "Get"
});
Upvotes: 2