@ URL. actionlink and @ URL. Action

Source: Internet
Author: User
Tags actionlink

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>

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.