[RESOLVED]How to combine 2 strings and assign the value to href?

Hi,

I’m working on a MVC3 app, using c#, razor view. I need to put an email icon to a page, where clicking on it will bring a email window up, such as outlook.

I need to pre-populate the email subject and body, like this:

<a href="mailto:youremailaddress?subject=My%20Email%20Suject!&amp;body=See%20if%20you%20like%20this:%0D%0A" + "@Session["mywebsite_ur"]">

Now – everything works except the value of the session variable does not show up – the outlook window shows up, with the subject, and the sentence for email boday, but not the value from Session["mywebsite_ur"].

I have tried various way, such as:

<a href="mailto:youremailaddress?subject=My%20Email%20Suject!&amp;body=See%20if%20you%20like%20this:%0D%0A" +
"@Session["mywebsite_ur"]">

But I have not made it work yet.

Note: this session var does have the correct value on this page – I tested it already.

I tried to add a new string var, assign the combined string to it, the just assign this string to "href="…but I’m not sure how to make it work.

Anyone can give a hint on how to make this work?

Thanks,

Claudia

Did you try

<a href="mailto:youremailaddress?subject=My%20Email%20Suject!&amp;body=See%20if%20you%20like%20this:%0D%0A@Session["mywebsite_ur"]">

?

+ stays for concatenation but there is no concatenation because <a href=… is an html and @… (in your case @Session) is a server code.

try this

@{

    var webaddr = Session["mywebsite_ur"].ToString();

    <a href='mailto:toemail@somthing.com?subject=subject words&body=See if you like this! @webaddr'>Email Me</a>
}

Hi smirnov,

Yes I tried that – it does not work.

Any new suggestions?

Thanks,

Claudia

Sorry my bad, just add ( ) around it.

<a href="mailto...@(Session["mywebsite_ur"])">

Thanks smirnov, it worked!!

Appreciate it,

Claudia

Leave a Reply