Reputation: 1013
I have a view with a model that has an email address. How do I create an anchor? to allow the user to simply click on it an open Outlook? I could create an anchor manually but then how do I include the email address?
<a href="mailto:" + Model.CreatorEmail >Email</a>
Upvotes: 0
Views: 2220
Reputation: 10354
Adding the email address attribute to your model:
[EmailAddress(ErrorMessage = "Must be a valid email address")]
And using a Html.DisplayFor
in your razor view
@Html.DisplayFor(x => x.EmailAddress)
Should render it as an a tag with
mailto:
before it's value
Upvotes: 0
Reputation:
Just use the @ syntax
<a href="mailto:@(Model.CreatorEmail)">Email</a>
Upvotes: 4
Reputation: 1013
I found an answer to my problem:
@{ var email = "mailto:" + Model.CreatorEmail;}
<a href="@email">Email</a>
Upvotes: 0