Asp.net mvc routing - rewrite url?

You can do it a couple of ways, one way would be to have a controller for each area and each controller to have one Index action. This would create Urls as required with limited configuration of routing The other method would be to have one controller and multiple actions (one for each Home , AboutUs, Products) and set the route to be something like this (untested) public static void RegisterRoutes(RouteCollection routes) { routes. IgnoreRoute("{resource}.

Axd/{*pathInfo}"); routes. MapRoute( "Default", // Route name "/{action}/{id}", // URL with parameters new { controller = "Home", action = "Home", id = UrlParameter. Optional } // Parameter defaults ); } Hope this helps Edit Just checked the following code with the following assumptions 1 Controller (HomeController) In Global.

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

MapRoute( "Default", // Route name "{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter. Optional } // Parameter defaults ); } In HomeController public class HomeController : Controller { public ActionResult Index() { ViewData"Message" = "Welcome to ASP. NET MVC!"; return View(); } public ActionResult AboutUs() { return View(); } } This will allow for: http://localhost:port http://localhost:port/index http://localhost:port/aboutus.

You can do it a couple of ways, one way would be to have a controller for each area and each controller to have one Index action. This would create Urls as required with limited configuration of routing. The other method would be to have one controller and multiple actions (one for each Home , AboutUs, Products) and set the route to be something like this (untested) ... public static void RegisterRoutes(RouteCollection routes) { routes.

IgnoreRoute("{resource}. Axd/{*pathInfo}"); routes. MapRoute( "Default", // Route name "/{action}/{id}", // URL with parameters new { controller = "Home", action = "Home", id = UrlParameter.

Optional } // Parameter defaults ); } Hope this helps. Edit Just checked the following code with the following assumptions - 1 Controller (HomeController) In Global. Ascx public static void RegisterRoutes(RouteCollection routes) { routes.

IgnoreRoute("{resource}. Axd/{*pathInfo}"); routes. MapRoute( "Default", // Route name "{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = UrlParameter.

Optional } // Parameter defaults ); } In HomeController public class HomeController : Controller { public ActionResult Index() { ViewData"Message" = "Welcome to ASP. NET MVC! "; return View(); } public ActionResult AboutUs() { return View(); } } This will allow for: http://localhost:port/ http://localhost:port/index http://localhost:port/aboutus.

I created controllers for each page. And each controller has action. But I didn't understood how to show just an action in my url.

Like: localhost:34534/AboutUs etc. – Ragims Ragimovs Sep 29 '10 at 8:31 If you have one controller and multiple actions its simple (see update). If you have a one to one mapping of controller / action then its doable. However, if you want multiple controllers/actions then it gets tricky as you need to know which controller the action refers to.

This could potentially be done with a custom Controller factory and some sort of lookup. – WestDiscGolf Sep 29 '10 at 10:52.

I would have a "Home" controller with the "Home"/"Index" action for "localhost:54594/Home". And for "localhost:54594/AboutUs" i'd use the "Home" controller too with an action "AboutUs". For "localhost:54594/Products" i'd have it's own controller as it's likely to be more complex.

The default route should serve ok for this. I'd route "/AboutUs" to the "/Home/AboutUs" action with something like this: routes. MapRoute( "AboutUs_Shortcut", "AboutUs", new { controller = "Home", action = "AboutUs" } ).

It is exactly opposite of that I want to do :) – Ragims Ragimovs Sep 29 '10 at 8:46.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions