【问题标题】:ASP NET MVC href to an image?ASP NET MVC href 到图像?
【发布时间】:2016-08-04 11:03:08
【问题描述】:

我有以下剃刀语法从控制器(从数据库表)获取图片:

<img src="@Url.Action("GetMainPicture", "Product", new { item.ProductID, @class = "img-responsive" })" height="300" width="230" alt="" />

效果很好,我可以在&lt;img&gt; 标签中获取图像,如您在上面的代码中所见。 现在在我为我的项目下载的模板中,我在下面有这个,这是一个href,带有一个按钮,可以用花哨的框缩放图像:

<a href="../../assets/frontend/pages/img/products/model1.jpg" class="btn btn-default fancybox-button">Zoom</a>

如果我给出图像的直接路径(文件夹中的图像的路径或非数据库的路径),上面的代码行有效,但我无法让它从数据库中获取图像,然后将其显示在花哨的盒子哪个更花哨。 谢谢! 编辑:不要忘记图像在数据库表中。

【问题讨论】:

  • 您总是可以创建一个处理程序 .ashx 来接收产品的 Id 并从数据表中返回图像。
  • 任何例子或只是一个链接来获取知识? @SílvioN。
  • 误解了这个问题。已经删除了我的答案。
  • @NaserDostdar 你的@Url.Action("GetMainPicture", "Product", new { item.ProductID, @class = "img-responsive" }) 应该返回一个文件,对吗?那么当你将它与锚标签href和缩放一起使用时会发生什么?该文件必须像物理路径一样被提取..
  • 什么都没发生,给我一个错误@Reddy

标签: html css asp.net-mvc href


【解决方案1】:

你必须把完整的网址放在那里,我认为没有../

【讨论】:

    【解决方案2】:

    但现在我想要一个指向该特定图片的 href(链接) 我该怎么做?

    您只需将图像包装在锚标记中即可。

    <a href="someURL">
     <img src="@Url.Action("GetMainPicture", "Product", new { item.ProductID, @class = "img-responsive" })" height="300" width="230" alt="" />
    </a>
    

    【讨论】:

    • 这不是我想要的!
    • @NaserDostdar 哦,我的错,你能解释一下你的要求,更好地用更多细节编辑你的问题。我会尽快删除这个答案..
    • 这个问题很快就会更新,请检查并回答我,谢谢
    • @NaserDostdar 是的,我明白你的问题,我会更新我的答案。
    【解决方案3】:

    你可以像下面那样做。将锚标签()的href属性设置为您想要的位置或用户点击图片时想要执行的操作。

    <a href="@Url.Action("GetMainPicture", "Product", new { item.ProductID})">
                        <img src="@Url.Action("GetMainPicture", "Product", new { item.ProductID, @class = "img-responsive" })" height="300" width="230" alt="" />
                    </a>
    

    【讨论】:

      【解决方案4】:
           <a href="@Url.Action("GetMainPicture", "Product", new { item.ProductID)">
             <img src="@Url.Content(@item.image)" class="img-responsive " style="height="300" width="230"" alt="@item.ContName" />
      </a>
      

      我已经使用这种方法将客户带到一个新表单,他可以在其中获取有关产品的所有详细信息,这对我有用,因此它可能会对您有所帮助

      【讨论】:

        【解决方案5】:

        在剃须刀中使用图片链接和Url.Content,如下例所示:

        <img src="@Url.Content(item.Image)" alt="MyImage" />
        

        或:

        <a href="@Url.Content(item.Image)">Load Image</a>
        

        【讨论】:

          猜你喜欢
          • 2013-07-14
          • 1970-01-01
          • 2020-06-14
          • 2022-01-05
          • 1970-01-01
          • 2016-03-30
          • 1970-01-01
          • 1970-01-01
          • 2011-02-22
          相关资源
          最近更新 更多