跨控制器的ActionLink

时间:2012-08-15 10:36:23

标签: asp.net-mvc vb.net asp.net-mvc-3 razor

我正在尝试在我的控制器RequestedService的视图中创建一个操作链接,该操作链接将用户带到另一个控制器并执行以下形式的操作:

/ ItemsForService /创建/ {ID}

使用ItemsForService作为创建函数所在的控制器。

到目前为止,我有:

@Html.ActionLink("Add Item", "ItemsForService", "Create", New With {.id = currentItem.RequestedServiceId})

然而,这似乎将其作为Create?= id传递而不是Create / id

我如何通过后者?

1 个答案:

答案 0 :(得分:0)

使用正确的ActionLink重载来获得预期的结果

@Html.ActionLink("Add Item", "ItemsForService", "Create", New With { id = currentItem. currentItem }, Nothing)

您不需要.id = ...只是id = ...

重载是ActionLink(string linkText, string actionName, string controllerName, object routeValues, object htmlAttributes)

在为操作提供参数时,必须将Nothing的最后一个参数添加为空HTML属性。或者,如果您确实需要将HTML属性应用于链接,则可以使用:

@Html.ActionLink("Add Item", "ItemsForService", "Create", New With { id = currentItem. currentItem }, New With { @class = "MyCustomCssClassName" } )
相关问题