How to concatenate two lines in an <img> src tag?

Here I want to combine two lines inside a tag <img>. How to do it?

<img src=" "/partners" + @item.AdPath" alt="" id="adimg" title="@item.AdName"  width:"50px" height="50px"/>

Any suggestion?

+5
source share
3 answers

You should just do this:

<img src="/partners+@(item.AdPath)" alt="" id="adimg"
    title="@item.AdName"  width:"50px" height="50px"/>

The Razor engine will replace @item.AdPaththe actual value by providing you src="/partners+[value]".

Since the Razor expression is the only one that is parsed, you do not need to try to use the string concatenation logic in the tag - just omit the Razor expression where you want the value to be displayed.

Edit: Or, if you don't need a plus sign (unclear from your comments):

<img src="/partners@(item.AdPath)" alt="" id="adimg"
    title="@item.AdName"  width:"50px" height="50px"/>

Alternatively you can try String.Format:

<img src="@String.Format("/partners{0}", item.AdPath)" alt="" id="adimg"
    title="@item.AdName"  width:"50px" height="50px"/>
+9
source

This can be done as follows:

-:

<img src="@("/partners" + item.AdPath)" alt="" id="adimg" title="@item.AdName"  width:"50px" height="50px"/>

-:

<img src="/partners@(item.AdPath)" alt="" id="adimg" title="@item.AdName"  width:"50px" height="50px"/>
+2

, , , .

<img src='<%#: String.Format("~/partners/{0}", item.AdPath) %>'
 alt="" id="adimg" title="<%#:item.AdName%>"  width:"50px" height="50px"/>
-1
source

All Articles