简体   繁体   English

ASP.Net MVC路由

[英]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 :/ 我试图在我的ASP.NET MVC C#应用程序中设置一个简单的路由系统,但它不起作用:/

Here is my root " http://localhost/Admin/ " or " http://localhost/Admin/Home.mvc/Index " 这是我的根目录“ http:// localhost / Admin / ”或“ http://localhost/Admin/Home.mvc/Index

I have a HomeController which manages an Index and a Start page. 我有一个HomeController,它管理索引和开始页面。

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. 在“索引”页面中,我有一个客户端列表可供选择(按钮或其他按钮),我想在选定客户端功能的基础上转到“ http:// localhost / StoreV3Admin / {client} /Home.mvc/Start” 。

I did some research on it but I don't completely understand how the routing system works. 我对此进行了一些研究,但我不完全了解路由系统的工作方式。

Firstly, is it possible?? 首先,有可能吗?

Thx. 谢谢。

I just threw together a simple mvc app, and I was able to get what you described to work just fine. 我只是集合了一个简单的mvc应用程序,就可以使您所描述的工作正常。

In my global.asax.cs, in the RegisterRoutes method, I added the following route: 在我的global.asax.cs的RegisterRoutes方法中,添加了以下路由:

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. 我认为您的MVC应用程序必须驻留在应用程序根目录中才能正常运行。 Try creating a VirtualDirectory in IIS and see if that helps. 尝试在IIS中创建VirtualDirectory,看看是否有帮助。

And why do you have a ".mvc" in your route? 以及为什么您的路由中包含“ .mvc”? Don't you just mean http://localhost/Admnin/Home/Index ? 您不是只说http://localhost/Admnin/Home/Index吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM