views:

141

answers:

4
Html.ActionLink("<span class=\"title\">Retry</span><span class=\"arrow\"></span>", "Login", "User")

Hi,

If I execute above code in ASP.Net MVC 2, I get the following output on my screen: Error?

How do I disable the escaping of the code, so my span is within the ActionLink, and not displayed as output?

I know this is expected behavior, to keep it safe, but I want it to interpret the HTML code I pass as a parameter.

Thanks! Yvan

+3  A: 

The ActionLink helper method can only be used for plain-text links.

You should manually make an <a> tag, like this:

<a href="<%=Url.Action("Login", "User") %>">
    <span class="title">Retry</span><span class="arrow"></span>
</a>
SLaks
How should I do that? I know how to make an <a> tag, but which must be the href parameter? I'm quite new to all this MVC-stuff ;)
Yvan JANSSENS
@Yvan: See my sample.
SLaks
Thank you! This helped me out, since I want to deploy on IIS 6, and from the things I read, I need to change some settings, which will render hardcoded paths in the href parameter invalid.
Yvan JANSSENS
A: 

how to generate below Url.Action (html) using html helper at run time ?

<a href="<%=Url.Action("Login", "User") %>"> 
    <span class="title">Retry</span><span class="arrow"></span> 
</a> 
A: 

I think the following also works.

<span class="title"><%= html.actionlink("Retry","Login", "User") %></span><span 
class="arrow"></span>

I mean, <.span>Retry<./span> is just <.span>plaintext<./span> which is the same as the actionlink text? ("." inserted for SO)

bastijn
A: 

I want use span within link text because i want to apply css only to part of link text (not whole link text) So applying span around action link will apply for whole text.