Problem: I want to change "Continue Learning" to an image for display in actionlink. The results show that it is always a string for processing, and MVC does not help us with this.
@Html. actionlink ("Continue Learning","Learning","Item","HTTP", Strhostnamekaoji,"",New{Itemid = item. Itemid, resourceid =Item. laststudyuserresid },New{})
Solution:
First, you can either rewrite the actionlink and perform the processing.
Public Static Mvchtmlstring actionlinkwithimage ( This Htmlhelper HTML, String Imgsrc, String Img_classname, String Img_width, String Img_height,
String Actionname, String Controllername, system. Web. Routing. routevaluedictionary routevalues, String Protocolname,String Hostname ){ VaR Urlhelper = New Urlhelper (html. viewcontext. requestcontext ); String Imgurl = Urlhelper. Content (imgsrc); tagbuilder imgtagbuilder = New Tagbuilder ( " IMG " ); Imgtagbuilder. mergeattribute ( " SRC " , Imgurl); imgtagbuilder. mergeattribute ( " Class " , Img_classname); imgtagbuilder. mergeattribute ( " Width " , Img_width); imgtagbuilder. mergeattribute ( " Height " , Img_height ); String IMG = Imgtagbuilder. tostring (tagrendermode. selfclosing ); String Url = Urlhelper. Action (actionname, controllername, routevalues, protocolname, hostname); tagbuilder = New Tagbuilder ( " A " ) {Innerhtml = IMG}; tagbuilder. mergeattribute ( " Href " , URL ); Return New Mvchtmlstring (tagbuilder. tostring (tagrendermode. Normal ));}
@ Html. actionlinkwithimage (item. res_item.img.tocdn (),"","63","63","Info","Item",NewRoutevaluedictionary (querystringdic ),"HTTP", Strhostnamekaoji)
Type 2: change to URL. Action.
@ { VaR Parsed = httputility. parsequerystring ( " Itemid = " + Item. Itemid + " & Resourceid = " + Item. laststudyuserresid); dictionary < String , Object > Querystringdic = parsed. allkeys. todictionary (k => K, K => ( Object ) Parsed [k]);} <A href = " @ URL. Action ( " Learning " , " Item " , New routevaluedictionary (querystringdic ), " HTTP " , Strhostnamekaoji) " > " 63 " Height = " 63 " Src = " @ (Item. res_item.img.tocdn ()) " /> </A>