Home > DeveloperSection > Forums > MVC routing the index page
Allen Scott

Total Post:36

Points:254
Posted on    May-19-2015 4:13 AM

 ASP.NET MVC Routing 
Ratings:


 1 Reply(s)
 522  View(s)
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);

 }



Kamlakar Singh
Kamlakar Singh

Total Post:194

Points:1396
Posted on    May-19-2015 6:12 AM

    Try this following:

     routes.MapRoute(

            name: "Custom",

            url: "{name}",

            defaults: new

            {

                    controller = "Home",

                    action = "Get"

            });


Don't want to miss updates? Please click the below button!

Follow MindStick