我的Model
有图像文件名。我想将文件名附加到href
@foreach (var images in Model)
{
//href="~/ImageGallery/"@images.imgname
//which is href="~/ImageGallery/cat.jpg"
<a href="~/ImageGallery/" title="Banana" data-gallery>
<img src="~/ImageGallery/thumbnails/" alt="Banana">
</a>
}
怎么做?
答案 0 :(得分:4)
@foreach (var images in Model)
{
<a href="~/ImageGallery/@(images.imgname)" title="Banana" data-gallery>
<img src="~/ImageGallery/thumbnails/" alt="Banana">
</a>
}
我希望你使用Url.Content()
帮助器虽然上面的块也可以,但@Url.Content()
从相对url生成正确的url:
@foreach (var images in Model)
{
<a href="@Url.Content("~/ImageGallery/"+images.imgname)" title="Banana" data-gallery>
<img src="~/ImageGallery/thumbnails/" alt="Banana">
</a>
}