我正在尝试使用Html.ActionLink以这种形式生成链接:
/动作/型号/ ID /参数1 /参数2
我用过: <%= Html.ActionLink("Link Text", "Action", "Model", new { id = var, parament1=var1 }, null) %>但它总是看起来像/ Action /型号/编号?参数1 =可变
我在Stackoverflow和其他地方看到了类似的问题,但我找不到一个有效/有意义的解决方案。 任何帮助,将不胜感激。
@John:我注册了以下路线: routes.MapRoute("Alternate","{controller}/{action}/{id}/{Heading}", new { controller = "Designation", action = "Details", id = "", Heading = "" }
然后我在我的视图中有以下代码: <%= Html.ActionLink("Link Text", "Action", "Model", new { Id = model.Id, Heading = model.Heading }, null) %>
我得到/ Model / Action / Id?标题= var1我希望它为/ Model / Action / Id / var1
解答:我在global.asax.cs文件中添加了以下路由,并正确生成了链接。 routes.MapRoute(“Something”,“MyModel / MyAction / {Id} / {Heading}”,new {controller =“MyModel”,action =“MyAction”,id =“”,heading =“”},new {controller = @“[^。] *”});
I'm trying to use Html.ActionLink to generate a link with in this form:
/Action/Model/Id/Parameter1/Parameter2
I've used: <%= Html.ActionLink("Link Text", "Action", "Model", new { id = var, parament1=var1 }, null) %> but it always ends up looking like /Action/Model/Id?parameter1=variable
I've seen similar questions on Stackoverflow and elsewhere, but I can't find a solution that works/makes sense. Any help would be appreciated.
@John: I have the following route registered: routes.MapRoute("Alternate","{controller}/{action}/{id}/{Heading}", new { controller = "Designation", action = "Details", id = "", Heading = "" }
I then have the following code in my view: <%= Html.ActionLink("Link Text", "Action", "Model", new { Id = model.Id, Heading = model.Heading }, null) %>
I get /Model/Action/Id?Heading=var1 I want it as /Model/Action/Id/var1
ANSWER: I added the following route to my global.asax.cs file and the links generated correctly. routes.MapRoute("Something", "MyModel/MyAction/{Id}/{Heading}", new { controller = "MyModel", action = "MyAction", id = "", heading = "" }, new { controller = @"[^.]*" });
最满意答案
这是一篇非常好的文章,你应该阅读http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx
Here is an excelent article you should read http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx
更多推荐
发布评论