c# - How can i display image in image link? -
i want create image link can't see image it's extension methods:
public static mvchtmlstring actionimage(this htmlhelper htmlhelper, string controller, string action, object routevalues, string imagepath, string alternatetext = "", object htmlattributes = null) { var anchorbuilder = new tagbuilder("a"); var url = new urlhelper(htmlhelper.viewcontext.requestcontext); anchorbuilder.mergeattribute("href", url.action(action, controller, routevalues)); var imgbuilder = new tagbuilder("img"); imgbuilder.mergeattribute("src", url.content(imagepath)); imgbuilder.mergeattribute("alt", alternatetext); var attributes = (idictionary<string, object>)htmlhelper.anonymousobjecttohtmlattributes(htmlattributes); imgbuilder.mergeattributes(attributes); string imghtml = imgbuilder.tostring(tagrendermode.selfclosing); anchorbuilder.innerhtml = imghtml; return mvchtmlstring.create(anchorbuilder.tostring()); }
and using in view:
@foreach (var item in model) { . . <div> image: @html.actionimage("controllername", "action", "routevalues", item.imageaddress.tostring()) </div> . . }
imageaddress string doesn't work,there no difference when use specific address like
@html.actionimage("controllername", "action", "routevalues", "c:\1.jpg")
only when use address work good:
"../../content/images/1.jpg"
what's problem? help, sorry english
browsers cannot read files server's disk.
you can reference images on http.
Comments
Post a Comment