Razor Html.ActionLink Parameters

2019-05-16 19:52发布

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条回答
一纸荒年 Trace。
2楼-- · 2019-05-16 20:19

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

查看更多
登录 后发表回答