How to correctly encode MailTo links in ASP.NET MVC?

Viewed 7656

I have the following mailto link on an ASP.NET MVC 5 application:

<a rel="nofollow" href="@(
  String.Format("mailto:?subject={0}&amp;body={1}", 
    "The title", "The description" + "%0D%0A" + "http://theurl.xyz")">
  share by email
</a>

This is not validating on HTML Validator. I get the error:

Bad value mailto:?subject=The subject&body=This is the url:%0D%0Ahttp://localhost:8580/home for attribute href on element a: Whitespace in query component. Use %20 in place of spaces.

I tried encoding using HttpUtility.UrlEncode but when I open the email I get "+" signs and others in the subject and body and I am not able to solve that.

3 Answers
Related