Ampersand is being HTML Encoded as &. Any way to prevent this?

DaveDev picture DaveDev · Feb 15, 2011 · Viewed 16.8k times · Source

I have the following block of code that creates an Action Link for a company.

Html.ActionLink(Html.Encode(currentCompany.GetDisplayName()), "CompanyFactsheet", "Company",
                                                       new {friendlyURL = currentCompany.FriendlyURL.ToLower()}, null)%>

Some of the company names contain '&', and this is being rendered as &

Is there a way that I can Html.Encode the company names, but still keep the & symbol as it's supposed to look, rather than &?

Answer

Stilgar picture Stilgar · Feb 15, 2011

It seems like you don't need to encode when using ActionLink helper method. It encodes internally:

How do I bypass the HTML encoding when using Html.ActionLink in Mvc?