Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MailTo link in Razor

How do I make a mailto link using Razor?

I've seen Html.MailTo, but when I try @Html.MailTo nothing comes up.

Thanks!

like image 783
aircan Avatar asked Aug 30 '11 22:08

aircan


2 Answers

HTML.MailTo() helper is a part of the 'mvc3 futures' project, but there is an alternative to way to do it.

1.)Create a new .cshtml file inside App_Code directory and name it as you want (for example HTMLHelpers.cshtml)

2.)Write the following in the file

@helper EmailTextBox(string email, string title) {
    <a href="mailto:@email">@title</a>    
}

3.)Now in your view you can call your new function. For example write

Email: @HTMLHelpers.EmailTextBox("[email protected]","George Chatzimanolis")
like image 39
GeoChatz Avatar answered Sep 24 '22 12:09

GeoChatz


You should just make a normal hyperlink:

<a href="mailto:[email protected]">...</a>

Razor and MVC helper methods are not intended to replace HTML tags; they're intended to make common data-bound elements simpler.

like image 73
SLaks Avatar answered Sep 22 '22 12:09

SLaks