4

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 Answer 1

6

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

4
  • Thank you, this works. What is "Nothing" in this example? Please tell me where I can find a comprehensive list of parameters like: Html.ActionLink(<string> title, <string> WhateverThisParamIs, etc.) Jul 26, 2012 at 18:36
  • @user1477388: That means we are passing Nothing as the HTMLAttributes. If you want to pass some custome HTML Attributes (CSS Class) you can replace Nothing with that. Check my updated answer.
    – Shyju
    Jul 26, 2012 at 18:38
  • Good answer, although I notice it doesn't work if I don't pass the "Nothing." I will have to remember that. Jul 26, 2012 at 18:44
  • 1
    @user1477388: Yea. because that overload needs a 5th parameter.Nothing means You have to write Nothing (VB.NET version of null)
    – Shyju
    Jul 26, 2012 at 18:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.