使用Html.ActionLink调用不同的控制器行动 [英] Using Html.ActionLink to call action on different controller
问题描述
我试图使用 ActionLink的
控制器之间进行导航。我会告诉我的问题用一个例子。
我在红帽控制器的索引视图,我试图用低于code创建一个链接到产品控制器的详细操作。
<%= Html.ActionLink(详细信息,详细信息,产品,新{ID = item.ID})%GT;
而不是创建一个链接到产品控制器的详细信息,这会产生下镲控制器详细信息的链接行动,并附加一个长度参数,它的结束:
帽子/详细信息/ 9?长度= 7
我不能够使用 HTML.ActionLink
来,因为这个问题的控制器之间切换。我将AP preciate如果你可以点我什么,我做错了。谢谢
PS:我用的是自带的MVC的默认路由设置
routes.MapRoute(默认,{控制器} / {行动} / {ID}
新{控制器=家,行动=索引,ID =});
你想要的是这个过载:
// LINKTEXT,actionName,controllerName,routeValues,htmlAttributes
<%= Html.ActionLink(详细信息,详细信息,
产品,新{ID = item.ID},NULL)%GT;
I am trying to navigate between controllers using ActionLink
. I will tell my problem with an example.
I am on Index view of Hat controller, and I am trying to use below code to create a link to Details action of Product controller.
<%= Html.ActionLink("Details", "Details", "Product", new { id=item.ID }) %>
Instead of creating a link to Details on Product controller, this generates a link to Details action under Hat controller and appends a Length parameter to the end of it:
Hat/Details/9?Length=7
I am not able to use HTML.ActionLink
to switch between controllers because of this problem. I will appreciate if you can point me to what I am doing wrong. Thanks
PS: I am using the default route setting that comes with MVC
routes.MapRoute("Default", "{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" } );
What you want is this overload :
//linkText, actionName, controllerName, routeValues, htmlAttributes
<%=Html.ActionLink("Details", "Details",
"Product", new {id = item.ID}, null) %>
这篇关于使用Html.ActionLink调用不同的控制器行动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!