Sunday, July 18, 2010

ASP.net MVC Routing - Part1


In ASP.net MVC Routing works following way and need to register in Application_Start of Global.asax

Default Route when ASP.net MVC Application created

routes.MapRoute(
   "Default", // Route name
   "{controller}/{action}/{id}", // URL with parameters
   new { controller = "Default", action = "Index", id = UrlParameter.Optional });

Default route has placeholder that done most of work.

For example :

if request is made for http://<<yoursite>//Home/Index.
This will call HomeController’s Index method.

if request is made for http://<<yousite>//Home/Index/1
This will call HomeController’s Index method with argument value “1”.

Sample Controller:
public class HomeController : Controller
    {      
        public ActionResult Index(string id)
        {
            return new ContentResult() { Content = "This is Index" };
        }
    }

Next Part will going to give you detail about “Slugish Url”.

No comments: