2011-09-01 19 views
9

Questo è inventato, ma è fondamentalmente quello che sto facendo. Ho un un @helper in questo modo:Un rasoio mvc @helper può restituire un tag non codificato?

@helper MyImage(int i) { 
    String s = "<img src='{0}' />"; 
    String theImage = ""; 
    switch(i) { 
     case 0: theImage = "test1.png"; break; 
     case 1: theImage = "test2.png"; break; 
     default: theImage = "error.png"; break; 
    } 
    String r = String.Format(s, theImage); 
    @(r) 
} 

L'uscita ottengo sulla pagina web è, naturalmente, la stringa effettiva:

<img src='test1.png' /> 

invece dell'immagine. C'è un modo per disabilitarlo dalla codifica in quel modo?

risposta

12

È possibile utilizzare @Html.Raw(r) anziché solo @(r).

+0

Perfetto. Grazie. – kailoon

Problemi correlati