Razor Html.ActionLink Parameters

2019-05-16 20:20发布

问题:

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

I want it to produce this, instead:

/Article/Details/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.

回答1:

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 page to see all available overloads