string testURL = 'www.google.com/just test'
StringBuilder emailBody = new StringBuilder();
emailBody.Append("<tr>");
emailBody.Append("<td> Just the URL </td>");
emailBody.Append("<td> String with href property </td>");
emailBody.Append("</tr>");
emailBody.Append("<tr>");
emailBody.Append("<td>" + testURL + "</td>"); // it displays: www.google.com/just test
emailBody.Append("<td> <a href=" + Uri.EscapeDataString(testURL) + ">" + name + "</a> </td>");
// the href property displays only: www.google.com/just
emailBody.Append("</tr>");
我怎样才能做到这一点?我尝试使用Uri.EscapeDataString()方法
答案 0 :(得分:1)
href的格式应为href="something"
而不是href=something
所以替换
emailBody.Append("<td> <a href=" + Uri.EscapeDataString(testURL) + ">" + name + "</a> </td>");
带
emailBody.Append("<td> <a href=\"" + Uri.EscapeDataString(testURL) + "\">" + name + " </a> </td>");
答案 1 :(得分:0)
你可以尝试
HttpUtility.UrlPathEncode(testURL)
答案 2 :(得分:0)
你应该试试这个
System.Web.HttpUtility.UrlEncode(string testURL)
答案 3 :(得分:0)
在testURL中用%20替换空格。