Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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")),
Posted

1 solution

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

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

-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900