How to display text in an MVC view with htmlattrbutes

前端 未结 3 1352
南方客
南方客 2021-01-26 11:31

I have the following code :

@Html.ActionLink(\"Hello \" + User.Identity.GetUserName() + \"!\", 
\"Manage\", \"Account\", 
routeValues: null, 
htmlAttributes: new         


        
相关标签:
3条回答
  • 2021-01-26 12:14

    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>
    
    0 讨论(0)
  • 2021-01-26 12:16

    I think you can use Url.Action method.

    <a href="@Url.Action("ActionName")">
      <span>"Hello " + User.Identity.GetUserName() + "!"</span>
    </a>
    
    0 讨论(0)
  • 2021-01-26 12:29

    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("Manage", "Account")">
        Hello @User.Identity.GetUserName()!
    </a>
    
    0 讨论(0)
提交回复
热议问题