MVC ROUTING THE INDEX PAGE

Allen Scott

Total Post:46

Points:324
Posted by  Allen Scott
 834  View(s)
Ratings:
Rate this:

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);

 }

  1. Kamlakar Singh

    Post:194

    Points:1396
    Re: MVC routing the index page

        Try this following:

         routes.MapRoute(

                name: "Custom",

                url: "{name}",

                defaults: new

                {

                        controller = "Home",

                        action = "Get"

                });

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!