views:

183

answers:

3

Hello,

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??

Thx.

A: 

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?

Tomas Lycken
I would appreciate if whoever voted me down would inform me of why, so that I can improve as an SO member and as a programmer. Thanks!
Tomas Lycken
You don't need to be in the root. Using .mvc is required in IIS6 if you don't use a wildcard mapping to send all requests to ASP.NET.
Jeff Putz
+2  A: 

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.

JohnRudolfLewis
A: 

Yep it works! Thank you!

Can we just do it with ActionLinks or is it possible to do that with buttons or a dropdown for example?

If someone gave you a correct answer, please mark it as "accepted".
womp