I have the following code :
@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!",
"Manage", "Account",
routeValues: null,
htmlAttributes: new { title = "Manage" })
I just want to display the text (with the correct htmlattribute) (i.e. no link)
Could you help me with the correct syntax please?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
I think you can use Url.Action method.
<a href="@Url.Action(" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"ActionName")">
<span>"Hello " + User.Identity.GetUserName() + "!"</span>
</a>
Method 2
If i understand correctly,you want to show the text inside your link without an achor tag, but with your html attributes (title attributes)
Try this
<span title="Manage">Hello @User.Identity.GetUserName() !</span>
Method 3
If you want the text with no link i.e. no anchor element, then just use plain HTML
<span title="Manage">Hello @User.Identity.GetUserName()!</span>
Or if you don’t want to enclose it within a <span>
<text>Hello @User.Identity.GetUserName()!</text>
But with this you won’t get the title attribute since the text is not enclosed within an html tag with which to apply it to.
If you actually want an anchor then you could also use @Url.Action() in conjunction with plain HTML
<a title="Manage" href="@Url.Action(" rel="nofollow noreferrer noopener" rel="nofollow noreferrer noopener"Manage", "Account")">
Hello @User.Identity.GetUserName()!
</a>
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0