3
<a href="https://google.com" class="link" ></a>   

<a href="https://google.com" class="link" >Text Node</a>


@using (Html.Glass().BeginRenderLink(m => m.Link, new { @class = "link" }, true))
{

}

@Html.Glass().RenderLink(m => m.Link, new { @class = "link" }, true)

I can't understand this odd behavior, using BeginRenderLink renders the first anchor link without a text node, but using RenderLink renders the same anchor link but with a text node. Is there something I'm missing here? The end goal is to be able to wrap some HTML inside the using statement but I am stuck on this little problem.

9

The fact that BeginRenderLink does not render link text inside the <a> tag is not bug.

As Glass Mapper documentation says, BeginRenderLink is not really for displaying the default link text. You should use it if you want to add something custom inside your link.

The BeginRenderLink can be used to render a link that should contain multiple HTML elements rather than the simple text elements show in the RenderLink method. This is useful for when you might want to make images or other HTML elements links that still work within the Page Editor.

E.g.:

@using (BeginRenderLink(x => x.GeneralLink, isEditable: true))
{
    @RenderImage(x => x.Image)
}

You can read more in Glass Mapper Tutorial

  • Okay thank you, I think I better understand it's uses now. As the documentation says, you can use it to customize the HTML, so the fact that it doesn't display the text node is good, as I can choose where I want the text node to be displayed. Thanks buddy – Uchenna Okafor Nov 24 '17 at 11:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.