MVC routing the index page

I have very simple mvc application

When I type  http://localhost: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, get 404 error.

http://localhost:8080/jhon

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);
 }
Last updated:5/19/2015 6:12:27 AM

1 Answers

Anonymous User
Anonymous User

    Try this following:

     routes.MapRoute(
            name: 'Custom',
            url: '{name}',
            defaults: new
            {
                    controller = 'Home',
                    action = 'Get'
            });

Answer