假设我有一个类

public class ItemController:Controller
{
    public ActionResult Login(int id)
    {
        return View("Hi", id);
    }
}

在ItemController所在的Item文件夹之外的页面上,我想创建一个指向Login方法的链接。所以是哪种Html。我应该使用ActionLink方法,我应该传递什么参数?

具体来说,我正在寻找替代的方法

Html.ActionLink(article.Title,
    new { controller = "Articles", action = "Details",
          id = article.ArticleID })

在最近的ASP中已经退役。NET MVC的化身。


当前回答

这种类型使用:

@Html.ActionLink(“主页”,“索引”,“主页”)

MainPage:文本的名称 索引:动作视图 Home: homeecontroller

基本使用ActionLink

<html> <head> <meta name="viewport" content="width=device-width" /> <title>_Layout</title> <link href="@Url.Content("~/Content/bootsrap.min.css")" rel="stylesheet" type="text/css" /> </head> <body> <div class="container"> <div class="col-md-12"> <button class="btn btn-default" type="submit">@Html.ActionLink("AnaSayfa","Index","Home")</button> <button class="btn btn-default" type="submit">@Html.ActionLink("Hakkımızda", "Hakkimizda", "Home")</button> <button class="btn btn-default" type="submit">@Html.ActionLink("Iletişim", "Iletisim", "Home")</button> </div> @RenderBody() <div class="col-md-12" style="height:200px;background-image:url(/img/footer.jpg)"> </div> </div> </body> </html>

其他回答

这个呢

<%=Html.ActionLink("Get Involved", 
                   "Show", 
                   "Home", 
                   new 
                       { 
                           id = "GetInvolved" 
                       }, 
                   new { 
                           @class = "menuitem", 
                           id = "menu_getinvolved" 
                       }
                   )%>
Html.ActionLink(article.Title, "Login/" + article.ArticleID, 'Item") 

这种类型使用:

@Html.ActionLink(“主页”,“索引”,“主页”)

MainPage:文本的名称 索引:动作视图 Home: homeecontroller

基本使用ActionLink

<html> <head> <meta name="viewport" content="width=device-width" /> <title>_Layout</title> <link href="@Url.Content("~/Content/bootsrap.min.css")" rel="stylesheet" type="text/css" /> </head> <body> <div class="container"> <div class="col-md-12"> <button class="btn btn-default" type="submit">@Html.ActionLink("AnaSayfa","Index","Home")</button> <button class="btn btn-default" type="submit">@Html.ActionLink("Hakkımızda", "Hakkimizda", "Home")</button> <button class="btn btn-default" type="submit">@Html.ActionLink("Iletişim", "Iletisim", "Home")</button> </div> @RenderBody() <div class="col-md-12" style="height:200px;background-image:url(/img/footer.jpg)"> </div> </div> </body> </html>

我认为Joseph翻转了控制器和动作。首先是动作,然后是控制器。这个签名看起来有点奇怪。

为了澄清一些事情,这是一个有效的版本(改编自约瑟夫的例子):

Html.ActionLink(article.Title, 
    "Login",  // <-- ActionMethod
    "Item",   // <-- Controller Name
    new { id = article.ArticleID }, // <-- Route arguments.
    null  // <-- htmlArguments .. which are none
    )

与MVC5我已经这样做了,它是100%的工作代码....

@Html.ActionLink(department.Name, "Index", "Employee", new { 
                            departmentId = department.DepartmentID }, null)

你们可以从中得到启发…