You must Sign In to post a response.
  • Category: ASP.Net MVC

    What is the route data

    Hi,

    Could anyone tell me what is Route Data in mvc.

    Regards,
    venkat
  • #763366
    RouteData contains the values for a current requested route

    In the RoutConfig.cs we are registering the controller,action,id etc as follows

    public static void RegisterRoutes(RouteCollection routes)
    {
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
    }

    At the run time we can get this values using RoutData.

    RouteData.Values["Controller"],
    RouteData.Values["action"],
    RouteData.Values["id"]

    By Nathan
    Direction is important than speed

  • #763374
    Hello Venkateswarao,

    You can google this query. You will get more example of codes and theories about route data.

    In simple words Routing is the way of constructing meaningful URLs for a web request. RouteData.Values is used for accessing the values/querystring values inserted by the classes handling routing.

    You can go through some links for deep reference :
    http://www.dotnetspider.com/forum/337640-what-is-Default-Routes-In-aspnet-MVC.aspx

    http://www.dotnetspider.com/forum/341217-MVC-Controller-HTTPContext-is-NULL.aspx

    http://www.dotnetcurry.com/ShowArticle.aspx?ID=626

    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

  • #763395
    Hi,

    I would suggested you to go through the below link to know more about Route Data, "google.co.in/?gfe_rd=cr&ei=LGNdVti7D8z08wfpkofYAw&gws_rd=ssl#q=route+data+in+mvc".

    We are here to help you while you are facing any typical issues, we didn't work out to guide you how to start learning, if you search the same in google you may found N no of articles and post regarding the same, I request you to please go through those and still you have a doubt please let us know.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #763429
    Hi venkateswarao.

    Unlike asp.net applications , MVC applications work like url pattern.
    By creating mvc application you will find a Route.Config.cs file in App_Start folder.

    routes.MapRoute(
    name: "Default",
    url: "{controller}/{action}/{id}",
    defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );


    You can specify your own controller, action and id like below based on your requirement.
    controller="myownController"
    action="myview"
    id="10"

    Sridhar Thota.
    Editor: DNS Forum.


Sign In to post your comments