如何在Web网格中使用自定义html帮助器 [英] how to use custom html helper in web grid

查看:75
本文介绍了如何在Web网格中使用自定义html帮助器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在webgrid中使用html.image自定义html帮助器,但我不知道如何使用它来匹配web网格的签名。

下面是我的html帮助程序代码



公共静态类CustomHelpers

{

public static IHtmlString Image(这个HtmlHelper帮助器, string src,string height,string width)

{

var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);

var img =新的TagBuilder(img);

img.Attributes [alt] =[IMAGE];

img.MergeAttribute(Width,width);

img.MergeAttribute(height,height);

img.Attributes [src] = UrlHelper.GenerateContentUrl(src,helper.ViewContext.HttpContext);

返回MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing));

}

}





我的网格栏我在哪里在我的网格列中
我收到错误

grid.Column(MemberPhotoUrl,Photo,格式:item => Html.Image(, 100,100)),

I am using html.image a custom html helper in webgrid but i don't know how to use it with matching the signatures of web grid.
below is my html helper code

public static class CustomHelpers
{
public static IHtmlString Image(this HtmlHelper helper, string src, string height,string width)
{
var urlHelper = new UrlHelper(helper.ViewContext.RequestContext);
var img = new TagBuilder("img");
img.Attributes["alt"] = "[IMAGE]";
img.MergeAttribute("Width", width);
img.MergeAttribute("height", height);
img.Attributes["src"] = UrlHelper.GenerateContentUrl(src, helper.ViewContext.HttpContext);
return MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing));
}
}


my web grid column where i am using it
in my grid column i am getting error
grid.Column("MemberPhotoUrl","Photo",format:item=>Html.Image(,"100","100")),

推荐答案

如果你想在WebGrid中显示图像,你可以做类似的事情,

If you want to show the image in WebGrid, you can do something like,
grid.Column(format: (item) =>
                {
                        return Html.Raw(string.Format("<text><img src="\"{0}\"" alt="\"Image\"/"></img></text>", Url.Content("~/Content/images/preview-photo.gif")));
)



如果你能轻松做到,为什么会让事情变得困难! :)



-KR


Why make things difficult, if you can do it easily ! :)

-KR


这篇关于如何在Web网格中使用自定义html帮助器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆