I am trying to create an email link using MVC3 and strongly typed modeling. I want the subject of the email to contain the # sign similar to:
Request #56
My initial attempt looked like:
<a href = "mailto:@Model.Email?subject=Request #@Model.ID">@Model.Name</a>
It resulted in what I thought was perfect HTML:
<a href="mailto:john.stone@nowhere.com?subject=Request #5">John Stone</a>
I found out that Internet Explorer does not like the # sign in the subject. If I clicked on the above “link”, the subject would be set to:
Request
After searching here, I found that I needed to use %23 in place of the #. So my second attempt looked like:
<a href = "mailto:@Model.Email?subject=Request %23 @Model.ID">@Model.Name</a>
This resulted in the following:
Request # 56
Close but I do not want the space between the # and the number.
How do I properly use the # key without a space?
I am using MVC3 and trying to get this to work in IE8.
*added some details about the first attempt resulting html and how IE handles the subject
SOLUTION
There are actually two issues going on.
The first is IE will not allow the # in the subject text. So any instance of the # needs to be replaced with %23.
The second is the MVC3 parser does NOT handle #23@Model.ID correctly. It will NOT substitue in the value of Model.ID.
The correct solution is noted below but to “cut and paste”:
@{
string requestValue = "%23" + Model.ID.ToString()
}
<a href = "mailto:@Model.Email?subject=Request @requestValue">@Model.Name</a>
The above will generate a properly clickable href mail link that would look like:
<a href="mailto:john.stone@nowhere.com?subject=Request %235">John Stone</a>
When the above is clicked, the subject of the email will be “Request #5”.
You can use an inline C# statement.