Here I want to concatenate two strings inside a <img>
tag. How to do this??
<img src=" "/partners" + @item.AdPath" alt="" id="adimg" title="@item.AdName" width:"50px" height="50px"/>
Any suggestion?
You should simply be able to do this:
<img src="/partners+@(item.AdPath)" alt="" id="adimg"
title="@item.AdName" width:"50px" height="50px"/>
The Razor engine will replace @item.AdPath
with the actual value, giving you src="/partners+[value]"
.
Since the Razor expression is the only thing that's parsed, you don't have to try and work string concatenation logic into the tag - simply drop in the Razor expression where you want the value to appear.
Edit: Or, if you don't want the plus sign (not clear from your comments):
<img src="/partners@(item.AdPath)" alt="" id="adimg"
title="@item.AdName" width:"50px" height="50px"/>
Alternatively, you could try with String.Format
:
<img src="@String.Format("/partners{0}", item.AdPath)" alt="" id="adimg"
title="@item.AdName" width:"50px" height="50px"/>
It could be done like this:
First:
<img src="@("/partners" + item.AdPath)" alt="" id="adimg" title="@item.AdName" width:"50px" height="50px"/>
Second:
<img src="/partners@(item.AdPath)" alt="" id="adimg" title="@item.AdName" width:"50px" height="50px"/>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With