2013-03-06 55 views
1

將mailto添加到此ASP.NET MVC3代碼的正確語法是什麼?這不工作,既沒有使用雙引號的作用:如何在模型錯誤消息中包含mailto鏈接

ModelState.AddModelError("", "We could not locate the email address you entered. Please check the email address. If you believe it is correct, please contact us by sending an email to <a href='mailto:[email protected]'>Support</a> from the email address you are attempting to use."); 
+2

你是什麼意思 「不工作」?你得到什麼HTML? – 2013-03-06 13:56:01

+0

這是什麼在瀏覽器中顯示:一個電子郵件到Support radiusx2 2013-03-06 14:07:15

+0

所以這意味着文本正在編碼服務器端..恐怕沒有多少你可以做,除了可以添加全球JavaScript將其轉換爲實際的鏈接。如果可行,讓我知道,我會來樣。 – 2013-03-06 14:09:25

回答

0

我並不擅長剃刀但是這可以解決您的問題,現在

@Html.Raw(Html.ValidationSummary().ToString().Replace("[mailto]", "<a href='mailto:[email protected]'>Support</a>")) 

和您的郵件將包含此

ModelState.AddModelError("", "We could not locate the email address you entered. Please 
check the email address. If you believe it is correct, please contact us by sending an 
email to [mailto] from the email address you are attempting to use."); 

鏈接現在在視圖中添加的,而不是從服務器/控制器,與實際的鏈接替換您[mailto]並呼籲Html.Raw渲染在日的HTML Ë瀏覽器

0

嘗試使用

添加這個命名空間:Using System.Text

StringBuilder s=new StringBuilder(); 
    s.Append(We could not locate the email address you entered. Please check the email address. If you believe it is correct, please contact us by sending an email to "); 
    s.Append("<a href='mailto:[email protected]'>Support</a>"); 
    s.Append("from the email address you are attempting to use."); 
    ModelState.AddModelError("", s.ToString()); 
相關問題