【问题标题】:Bind images in razor view to <img src> that are in loop将 razor 视图中的图像绑定到循环中的 <img src>
【发布时间】:2017-11-16 14:04:15
【问题描述】:

现在我唯一想知道的是如何将图像绑定到剃刀视图中的“img src”。我已经搜索了其他问题,但没有找到循环中图像的答案。写下的当前方式不起作用。“~/Images/”是上传图片所在的文件夹。

@model List<propertyMgmt.Models.Property>
    <div id="propertyList">
          <label>Select properties to be Featured:</label><br />
          <table class="table">
            <tr>
              <th>
                @Html.Label("Property Description")
              </th>
              <th>
                @Html.Label("Property Cost")
              </th>
              <th>
                @Html.Label("Property Image")
              </th>
              <th>
                @Html.Label("Featured??")
              </th>
            </tr>
            @for (int i=0;i<Model.Count;i++)
            {
            <tr>
              <td>
                @Html.DisplayFor(m => m[i].PropertyDescription)
              </td>
              <td>
                @Html.DisplayFor(m => m[i].PropertyCost)
              </td>
              <td>
                <img src="~/Images/@(m=>m[i].PropertyImage)" />
              </td>
              <td>
                @Html.CheckBoxFor(m => m[i].IsFeatured, new { 
                @onclick = "propertyCheckBoxSelect(this)" })
              </td>
            </tr>
            }
          </table>
        </div>

【问题讨论】:

  • @Model[i].PropertyImage

标签: asp.net asp.net-mvc razor


【解决方案1】:

你可以这样使用。

<img src="~/Images/@(Model[i].PropertyImage)" />

【讨论】:

  • 谢谢 Nitesh :)
猜你喜欢
  • 2020-12-23
  • 2018-07-28
  • 2013-03-18
  • 1970-01-01
  • 2012-10-20
  • 1970-01-01
  • 1970-01-01
  • 2017-06-11
  • 2019-08-29
相关资源
最近更新 更多