Is it possible to use an ActionLink containing an element?

前端 未结 5 1409
[愿得一人]
[愿得一人] 2021-01-11 14:43

As the question says, Is it possible to use an ActionLink containing an element, and if not, what is the best way to achieve it?

For example, lets say I have a

相关标签:
5条回答
  • 2021-01-11 15:16

    You can not specify a html tag inside actionlink, but I can suggest you two solutions: 1 extend the actionlink with your function. So you can also implement actionlink that generate href with other htmal tag inside (img or span like in your case)

    2 using the url.content in the href. It's like your actual workaround but better because you use the rules you have defined in the global.asax instead of using "magic string"

    0 讨论(0)
  • 2021-01-11 15:21

    Just use @Url.Action instead:

    <a href="@Url.Action("Page","Site", new { id = Model.Id, @Type = "test" })">
     <span class="box5">Click anywhere in this box</span> </a>
    
    0 讨论(0)
  • 2021-01-11 15:25

    Just Write <span> </span> and in between the span use the @html>ActionLink Method It will work

    0 讨论(0)
  • 2021-01-11 15:29

    There's a hack you can use to work around the limitation

    @Html.Raw(
         Html
            .ActionLink("-replace-me-", .....)
            .ToString()
            .Replace(
                  "-replace-me-", 
                  @"<span class=""box5"">Click anywhere in this box</span>"))
    

    it's not elegant, but it does the job

    0 讨论(0)
  • 2021-01-11 15:36

    Html.ActionLink is just a plain old Extension Method to the HtmlHelper object.

    You can create your own custom extension methods for HtmlHelper as well, and they're pretty simple to do and will save you tons of time.

    0 讨论(0)
提交回复
热议问题