asp.net mvc 3 - .NET MVC3 routing - why so confusing? -


I do not know why I constantly struggle with it, but no one can tell why it does not work is? / redirects / from home controller / .

/ Gallery / A 404 error has not been found.

/ gallery / index index is the action of gallery controller.

From:

When you define a route, you can provide a default value for a parameter. The original value is used if the value for that parameter is not included in the URL. You set the default value for a root by specifying the default values ​​for an object to the root class.

I do not know that it does not follow this rule: (predefined), "{controller} / {action} / {id}", new {controller = "Home", Action = "Index", Id = UrlParameter.Optional}); }

I read this:

  • If no controller is defined, home Use
  • If any verb is not defined , then use index .
  • The entered URL contains the controller = gallery and no action is included in the URL so that it should go to index .

    Am I missing something or is this unnecessary confusing and silly?

    I have always found MVC3 routing problematic but have accepted it then I started playing with rail and node frameworks and now they are ridiculously simple routing. NIT MVC now annoys me when it does not work or does not use complex patterns.

    Someone asks for a reference, when I browse on / gallery / index then my gallery controller, action and view are all defined and working. Public Category GalleryController: Controller {Public Performance Index} {View Return (); }}

    You are definitely doing something wrong or some code that you Paradise is not followed by following these steps:

    1. Create a new ASP.NET MVC 3 application using the default wizard ( internet application )
    2. Change the contents of HomeController.cs with:

        Public Class Home Controller: Controller {Public Performance Index} {Return Content (" Home / index "); }} Public Class Gallery Controller: Controller {Public Performance Index} {Return Content ("Gallery / Index");  
    3. Hit F5

      What Happens Here:

        request url | Results ----------------- + --------------- / | Home / Index / Home | Home / Index / Home / | Home / Index / Home / Index | Home / Index / Home / Index / | Home / Index / Gallery | Gallery / Index / Gallery / | Gallery / Index / Gallery / Index | Gallery / Index / Gallery / Index / Gallery / Index   

      Actually Expected, right?

Comments