I was wondering what the best practice was for specifying an action on a certain controller.
Parts of the code I've been working on are specifying a url as:
<a href="/controller/action"/>
I'm generally not a big fan of this style. I've preferred to use:
<a href='@Url.Action("Action", "Controller")'/>
1) What is the best practice in forming urls for internal actions in this case? Both work, just wondering what is better.
2) Is there a benefit to using one versus the other?
Of the two options I would say the second is the better approach as it will work with virtual paths/directories:
<a href='@Url.Action("Action", "Controller")'/>
I prefer to use ActionLinks though:
@Html.ActionLink("text", "action", "controller")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With