I have the following model
public class EmailLinkModel
{
public string mailbody { get; set; }
public string emailSubject { get; set; }
public string emailto { get; set; }
}
mailbody contains the actual text which is a part of mail body. This text contains a long text [ contains special characters like ? < etc and can contain line breaks spaces etc] I want to create a mailto html tag in the partial view and i tried 3 different approaches and at some point my mailto link not opening the default mail client I think the reason was Html or Url ecnoding [ I am showing the mailbody content in a text area as well here to make sure value is coming correctly] Here is my view
@model RoyaltyDb.Models.EmailLinkModel
@{
Layout = null;
}
<div class="row ">
@{
var formatted_doc_data = Model.mailbody;
/*
var formatted_doc_data =HttpUtility.HtmlEncode(Model.mailbody);
*/
/* var formatted_doc_data = Model.mailbody.ToString().Trim().Replace("\n", "%0D%0A");
formatted_doc_data = formatted_doc_data.ToString().Trim().Replace(" ", "%20");
formatted_doc_data = formatted_doc_data.ToString().Trim().Replace(" ", "%20");
formatted_doc_data = formatted_doc_data.ToString().Trim().Replace("%", "%25");
formatted_doc_data = formatted_doc_data.ToString().Trim().Replace("?", "%3F");
formatted_doc_data = formatted_doc_data.ToString().Trim().Replace("/", "%2F");
formatted_doc_data = formatted_doc_data.ToString().Trim().Replace(":", "%3A");*/
}
<a class="btn btn-primary center" href="mailto:@Model.emailto?Subject=@Model.emailSubject&body=@formatted_doc_data" target="_top">Send Mail</a>
</div>
<hr/>
<div class="row">
@Html.TextAreaFor(m => m.mailbody, new { style = "width: 100%; height:200px;margin:5px 5px;" })
</div>
How can i do proper encoding to create the mailto Link