0

I have three url types. These:

first: http://localhost/
second: http://localhost/X/
third: http://localhost/X/Y/

Examples Url:

http://localhost/test/
http://localhost/test/details/

first:

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

public class HomeController : Controller
{
    // GET: /Home/

    public ActionResult Index()
    {
        return View();
    }

}

second:

routes.MapRoute(
            "Module",
            "{module_name}/{controller}/{action}", 
            new
            {
                controller = "Module",
                action = "Index",
                module_name = UrlParameter.Optional
            }
        );

public class ModuleController : Controller
{
    //
    // GET: /Module/

    public ActionResult Index(string modul_name)
    {
        return View();
    }

}

third:

routes.MapRoute(
      "ModuleDetails",
      "{module_name}/{details_param}/{controller}/{action}", 
      new
      {
          controller = "ModuleDetails",
          action = "Index",
          module_name = UrlParameter.Optional,
          details_param = UrlParameter.Optional
      }
);

public class ModuleDetailsController : Controller
{
    //
    // GET: /ModuleDetails/

    public ActionResult Index(string modul_name, string details_param)
    {
        return View();
    }

}

in this instance;

http://localhost/X/
response: "Home", "Index"

but;

http://localhost/X/
response: Application in the server error. Resource Not Found.

http://localhost/X/Y/
response: Application in the server error. Resource Not Found.

How can I do? Thanks, best regards..

2 Answers 2

2

http://localhost/X/ response: Application in the server error. Resource Not Found.

This happens because each of your routes specifies at least 2 mandatory parameters.

Try to add this one:

routes.MapRoute(
            "Default",
            "{controller}/{action}", 
            new
            {
                controller = "Home",
                action = "Index"
            }
        );
Sign up to request clarification or add additional context in comments.

Comments

0

that's right friends..

        routes.MapRoute(
            "Default", // Route name
            "", // URL with parameters
            new { controller = "Home", action = "Index" } // Parameter defaults
        );

        routes.MapRoute(
            "Module",
            "{modul_name}",
            new { controller = "Modul", action = "Index", modul_name = UrlParameter.Optional }
        );

        routes.MapRoute(
            "Page",
            "{modul_name}/{page_name}",
            new { controller = "Page", action = "Index", modul_name = UrlParameter.Optional, page_name = UrlParameter.Optional }
        );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.