I’m getting an odd result when trying to assign an ID attribute to an [a] tag created via the Razor @Html.ActionLink helper
My original code was this:
@Html.ActionLink("Create New Order", "Index", "NewOrder")
This works correctly and creates a link as http://www.mysite.com/NewOrder but I want to add an ID tag to my element.
I then tried this
@Html.ActionLink("Create New Order", "Index", "NewOrder", new {@id = "orderlink"})
This creates a link of http://www.mysite.com/Orders?Length=8
UPDATE:
When I use the solution provided,
@Html.ActionLink(“Create New Order”, “Index”, “NewOrder”, new { @id = “orderlink” }, null)
I get a link that looks like this:
http://www.mysite.com/NewOrder/Index/orderlink
I don’t want the orderlink added to my link/route. I want it added to the [a] tags attributes. See the top of the question.
I want to get this:
<a id="orderlink" href="/tcap/NewOrder/Index" >Create New Order</a>
Try this overload.
So your code will be
EDIT : As per your comment/ updated question
Use this overload
this will give you
mysite.com/NewOrder/IndexurlEDIT2 :
If you want,
<a id="orderlink" href="/tcap/NewOrder/Index" >Create New Order</a>Use this, pass HTML attributes as the fifth parameter of this overload