超链接调用操作方法

Pos*_*Guy 0 asp.net-mvc-3

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

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

更新:

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

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

Dar*_*rov 5

您可以从应用程序中的任何位置使用ActionLink帮助程序:

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

假设默认路由应该生成:

<a href="/?userid=123">call index</a>
Run Code Online (Sandbox Code Playgroud)