超文本标记语言构建图像参数

本文关键字:参数 图像 构建 超文本标记语言 | 更新日期: 2023-09-27 18:07:10

我有这个插件:ImageResizer.FluentExtensions.Mvc在我的项目。这个插件包含一个帮助器:Html。BuildImage和这个助手包含多个参数,我已经使用了参数:htmlatattributes,但不为我工作,我的代码:

@Html.BuildImage("~/content/images/produto-foto/"+ (fotoPrincipal != null ? fotoPrincipal.FotoID : 0) + ".jpg", builder => builder.Resize(img => img.Dimensions(224,187)),Model.title, new {@class="img-produto"})

这是响应我的html编译:

<img src="/content/images/produto-foto/8.jpg?width=224&amp;height=187" alt="">

有人知道我做错了什么吗?

PS: Sorry for my english

超文本标记语言构建图像参数

您已经链接到https://github.com/benfoster/ImageResizer.FluentExtensions作为Html.BuildImage实现的源代码。我可以找到这样一个方法的两个实现。

public static MvcHtmlString BuildImage(this HtmlHelper html, string src, Action<ImageUrlBuilder> configure, string alternateText = "", object htmlAttributes = null)
{
  var imageUrl = html.CreateUrlHelper().ImageUrl(src, configure);
  return html.Image(imageUrl.ToString());
}
public static MvcHtmlString BuildImage(this HtmlHelper html, string src, ImageUrlBuilder builder, string alternateText = "", object htmlAttributes = null)
{
  var imageUrl = html.CreateUrlHelper().ImageUrl(src, builder);
  return html.Image(imageUrl.ToString());
}

这两种方法都完全忽略了alternateTexthtmlAttributes参数,因此传递它们是无用的。

为了设置标题和类,您需要以不同的方式构建图像,或者手动更改BuildImage的输出。