Murali Bala
Murali Bala

Reputation: 43

MVC Routing the Index page

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

Answers (1)

emre nevayeshirazi
emre nevayeshirazi

Reputation: 19241

Following should work.

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

Upvotes: 2

Related Questions