Tutorial :ASP.Net MVC Routes


I'm trying to set a simple routing system in my ASP.NET MVC C# application and it doesn't work :/

Here is my root "http://localhost/Admin/" or "http://localhost/Admin/Home.mvc/Index"

I have a HomeController which manages an Index and a Start page.

In the Index page, I have a list of client to select (button or whatever) and I would like to go to "http://localhost/StoreV3Admin/{client}/Home.mvc/Start" in function of the client selected.

I did some research on it but I don't completely understand how the routing system works.

Firstly, is it possible??



I just threw together a simple mvc app, and I was able to get what you described to work just fine.

In my global.asax.cs, in the RegisterRoutes method, I added the following route:

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

In my controller, I declare a method like this:

public ActionResult FooBar(string client)  {      return View();  }  

In my view, I build links like this:

<p><%= Html.ActionLink("Client1", "FooBar", "Home", new { client = "Client1"}, null) %></p>  <p><%= Html.ActionLink("Client2", "FooBar", "Home", new { client = "Client2"}, null) %></p>  <p><%= Html.ActionLink("Client3", "FooBar", "Home", new { client = "Client3"}, null) %></p>  

And the resulting markup ends up looking like this:

<p><a href="/Client1/Home/FooBar">Client1</a></p>      <p><a href="/Client2/Home/FooBar">Client2</a></p>      <p><a href="/Client3/Home/FooBar">Client3</a></p>  

I hope this helps.


I think you MVC application has to reside in the applicaiton root to function properly. Try creating a VirtualDirectory in IIS and see if that helps.

And why do you have a ".mvc" in your route? Don't you just mean http://localhost/Admnin/Home/Index?

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »