Home > DeveloperSection > Forums > Dynamic MVC Routing in asp.net mvc
Chris S
Chris S

Total Post:48

Points:336
Posted on    November-09-2014 10:58 PM

 ASP.NET MVC Mvc 
Ratings:


 1 Reply(s)
 876  View(s)
Rate this:

I have Controller name: About and Action name: Index. But I want the URL to be like this (action name will be dynamically)

www.example.com/home/aaa www.example.com/home/bbb www.example.com/home/ccc

Routing

  routes.MapRoute(

                name: "Home",

                url: "{controller}/{name}",

                defaults: new { controller = "Home", action = "Index"}

Controller

public class AboutController : Controller

    {

        public ActionResult Index(string name)

        {

            return View();

        }

    }

}

View

@{

    ViewBag.Title = "Index";

}

<h2>Index About</h2>



Barbara Jones

Total Post:13

Points:91
Posted on    November-10-2014 12:59 AM

This should work.

routes.MapRoute(

    name: "Home",

    url: "Home/{name}",

    defaults: new

    {

        controller = "Home",

        action = "Index"

    });

Make sure your default route exists and comes after About route


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

Follow MindStick