Tips for using MVC html. actionlink

Source: Internet
Author: User
Tags actionlink

Actionlink

 

1. Add CSS to the link font. For example, add red

@ Html. actionlink ("<First page","Allmedias","Listenmedia",New{Page =1, Sortorder = viewbag. currentsort, currentfilter = viewbag. currentfilter },New{Style ="Color: red"})

2. If you append a parameter to the link, make sure that the following parameter is null. Otherwise, other methods will be reloaded, and the length of the ID will be passed in.

Html. actionlink ("Modify","Updatemediainfo","Listenmedia",New{Id = item. ID },Null)

If the Database Name of item. ID is ID. You can omit id =

Html. actionlink ("Modify","Updatemediainfo","Listenmedia",New{Item. ID },Null)

3. If it is opened in a new window (target = "_ blank ").

Html. actionlink (httputility. htmldecode (@ html. displayfor (x => item. Title). tostring ()), "  Showmedia  " , New {Item. ID, item. specialtitle },  New  {Target = "  _ Blank  ", Style = "color: Red"
})
 
 
 
 

4. If you click a delete link, the delete or not dialog box is displayed,

 
@ Html. actionlink ("delete this media from database", "deletemedia", "listenmedia", new {@ model. ID}, new {id = "reportlink "})

$ ('# Reportlink'). Click (Function(){VaRX = confirm ("delete from database? ");If(X =True) {// Do something}Else{Return False;}});

 

5. If the link Image

<A href ="@ URL. Action ("Cutimg","Listenmedia", New {item, id = viewbag. ID })"> <IMG id ="@ Item"Src ="@ Item"Width ="200"Height ="100"/> </A>

 

 

6.Html. Raw

If you want to output <br> XXX <br> as HTML to the page.

@ Item. Name: Double quotation marks are displayed as strings.

Use @ html.raw(viewbag.html content)

HTML is displayed on the page as HTML.

 

7. Sometimes you want to display a default value for @ html. textboxfor or @ html. editorfor, such as automatically generating a guid Value

According to the principle, it should be okay to write in this way.

 
@ Html. textboxfor (C => C. propertyname, new {@ value = "5 "})
 
@ Html. editorfor (C => C. propertyname, new {@ value = "5 "})

 But it does not work. Therefore, you must use HTML tags directly.

 <InputValue= "@ Guid. newguid ()"ID= "UUID"Name= "UUID"Type= "Text"Value= "" />

 

OK. Another method is to set the default value, but it is not flexible.

 
Public class myvm {int _ propertyvalue = 5; // set the default value public int propertyname {get {return _ propertyvalue ;}set {_ propertyvalue = value ;}}}

 

 

 

 

 

 

Will be added at any time!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Related Article

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.