I just to add some model elemen value to Url.Content and don't know how to do it.
Any clue?
Thank you!
Those lines don't work...
<img alt="" src="@Url.Content("~/Images/Houses/@(house.ImageFileName)")" />
<img alt="" src="@Url.Content("~/Images/Houses/@house.ImageFileName")" />
<img alt="" src="@Url.Content("~/Images/Houses/" + @house.ImageFileName + ")" />
You don't need the @
before your house
object
since you've already declared a code block with the first one at @Url
. But this is the best way below.
Assuming house
is a valid object
in the context
:
<img alt="" src="@Url.Content(String.Format("~/Images/Houses/{0}", house.ImageFileName))" />
您也可以尝试
<img alt="" src="@Url.Content("~/Images/Houses/" + house.ImageFileName)" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.