asp.net-mvc Razor Html.ActionLink 参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11675723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 02:07:45  来源:igfitidea点击:

Razor Html.ActionLink Parameters

asp.net-mvcvb.netasp.net-mvc-3razor

提问by user1477388

I have the following code in my view:

我认为有以下代码:

@Html.ActionLink(item.Title,  "Articles/Details", New With {.id = item.ArticleId})

It produces the following link:

它产生以下链接:

/Blog/Article/Details/1

/博客/文章/详细信息/1

I want it to produce this, instead:

我希望它产生这个,而不是:

/Article/Details/1

/文章/详情/1

I tried messing with the parameters, but I'm not sure how to make it do what I want. How can I do this? Thanks.

我试图弄乱参数,但我不知道如何让它做我想做的事。我怎样才能做到这一点?谢谢。

回答by Shyju

Use this overload

使用这个重载

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    string controllerName,
    Object routeValues,
    Object htmlAttributes
)

So your code can be written like

所以你的代码可以写成

@Html.ActionLink(item.Title, "Details","Article",
                  New With {.id = item.ArticleId},Nothing)

Check this msdn pageto see all available overloads

检查此 msdn 页面以查看所有可用的重载