0

Maybe silly question: I want Razor to generate link like this:

< a href="/AppName/ControllerName/ActionName/ID">
    http://MyServer/AppName/ControllerName/ActionName/ID
</a>

Note full URL as link text. Can I do it with

@Html.ActionLink(###???###, "MyActionName", "MyControllerName",new { id = Model.id },null)

What should go into ###???### place? It doesn't take null or empty string. I can manipulate Request URL of cause but that seems to be too complicated.

Any other methods?

Thank you!!!

shlasasha
  • 165
  • 1
  • 14

2 Answers2

0

the first parameter is the displayed name of the link so you can take look to the following code, it's VB but the order is same:

@Html.ActionLink("Langues", "EditLangues", "Home", New With {.id = 1}, New With {.class = "dropdown-item"})
  1. the displayed name of the link
  2. your view (.vbhtml or .cshtml)
  3. your controller name
  4. parameter when you want to open your page with some id for example
  5. is a class used for the style

more details with C# in an older post: HTML.ActionLink method

B.S.
  • 668
  • 1
  • 5
  • 15
  • Thank you for the answer but this will generate link with the word "Langues" as clickable text. I want clickable text to be the same as link itself: https ://server/app/controller/action – shlasasha Dec 08 '20 at 03:53
0

@Html.ActionLink("Admin", "Index", "Home", new { area = "Admin" }, null)

Found yet another HTML helper to solve this:

@Html.RouteLink("Admin", new { action = "Index", controller = "Home", area = "Admin" })

Pirate
  • 1,167
  • 1
  • 9
  • 19
  • Thank you for the answer but this will generate link with the word "Admin" as clickable text. I want clickable text to be the same as link itself. https ://server/app/controller/action – shlasasha Dec 08 '20 at 03:51
  • @Html.ActionLink("link text", "someaction", "somecontroller", new { id = "123" }, null) generates: link text and Url.Action("someaction", "somecontroller", new { id = "123" }) generates: /somecontroller/someaction/123 – farnaz_barahooei Dec 08 '20 at 10:18