Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • URL Routing in MVC

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 338
    Comment on it

    In MVC we build the application and run it . The main core behind the application is that it  will run from the controller name and the action name.

     

     

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

     

     

    This is the route page which contains entry for the Home controller by default and the action is Index.

     

     

     

    This means whenever the project gets run this controller action will be executed.

     

     

     public ActionResult Index()
            {
                EmpRep = new EmployeeRepository();
                List<EmployeeModel> EmpMod = new List<EmployeeModel>();
                EmpMod = EmpRep.GetDetails().ToList();
                return View(EmpMod);
            }
    

     

     

    Apart from it if you want to run any other action from the same controller or from the different controller you can it in the URL at run time.

     

    http://localhost:57851/Home/_Edit

     

     

    We have run the partial view _Edit which is inside the Home controller.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: