Html.ActionLink and Hyperlink Bookmarks (#bookmark)

Last post 03-18-2008 2:18 PM by TheDeathArt. 2 replies.

Sort Posts:

  • Html.ActionLink and Hyperlink Bookmarks (#bookmark)

    03-18-2008, 12:34 PM
    • Member
      123 point Member
    • TheDeathArt
    • Member since 06-28-2006, 6:26 PM
    • Denmark
    • Posts 50

    Hey

    I'm trying to create a hyperlink with a bookmark in the end, using a lambda expression in the html.ActionLink, however it does not appear to be possible.

    The case I'm working with is is the following:

    <%= Html.ActionLink<BlogController>(
            c => c.View(entity.BlogId),
            String.Format("Comments {0}",entity.Comments.Count)
        )
    %>

    This creates the following output:
        <a href="/Blog/View/1">Comments 2</a>

    However, I want to change the output to the following:
         <a href="/Blog/View/1#comments">Comments 2</a>

    But I'm yet to find any writings or documentation on how this is possible, and the htmlAttributes overload don't appear to have a option for this.


    Any input would be great, thanks. 

  • Re: Html.ActionLink and Hyperlink Bookmarks (#bookmark)

    03-18-2008, 1:38 PM
    Answer
    • Contributor
      4,360 point Contributor
    • tgmdbm
    • Member since 12-17-2007, 9:08 AM
    • Posts 882
    • ASPInsiders
      TrustedFriends-MVPs

    Good call.

    I suggest that there should be an option in htmlAttributes that does this.

    for now you'll have to either write your own helper method or write out the html in full.

    <a href="<%= LinkBuilder.BuildUrlFromExpression<BlogController>( c => c.View( ... ) ) %>#comments"><%= string.Format( ... ) %></a>

    Writing a helper method is easy and looks better in the view.

     

  • Re: Html.ActionLink and Hyperlink Bookmarks (#bookmark)

    03-18-2008, 2:18 PM
    • Member
      123 point Member
    • TheDeathArt
    • Member since 06-28-2006, 6:26 PM
    • Denmark
    • Posts 50
    Cool, didden't actually know about the LinkBuilder :-)

    Thanks for the help.
    Now all to do is hope someone with the right contacts see the issue, and it gets solved in a later version.

    It's a really nice framework \o/
Page 1 of 1 (3 items)