超链接调用操作方法

时间:2012-02-06 21:16:08

标签: asp.net-mvc-3

我正在试图找出一个简单的超链接创建(通过使用Html.ActionLink或纯超链接标记)来调用某个控制器操作并传入userId

让控制器具有索引操作。我在另一个不相关的视图中有一个超链接,我需要所有控制器的索引操作,并传入一个userId,它是action方法中的param。

更新

Html.ActionLink("Test Something", "Index", "Tests", new { @userId = @Model.User.UserId }, null)

这是我尝试过的一个例子。问题是,当我在运行时浏览网址时,它没有在网址中显示测试/

1 个答案:

答案 0 :(得分:5)

您可以在应用程序的任何位置使用ActionLink helper

@Html.ActionLink(
    "call index",            // linkText
    "index",                 // action
    "home",                  // controller
    new { userid = "123" },  // routeValue
    null                     // htmlAttributes
)

假设默认路由应该生成:

<a href="/?userid=123">call index</a>