Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to print HTML entities using String.Format

I have something like this inside my View:

@String.Format("{0} © Copyright by Nemanja", DateTime.Now.Year);

However, this is escaping my & into &. Is there any way to bypass this?

like image 878
Nemanja Boric Avatar asked Dec 01 '22 18:12

Nemanja Boric


2 Answers

You're looking for @Html.Raw(...), which will prevent that and create an XSS hole instead.

In your case, you can get rid of it entirely:

@DateTime.Now.Year © Copyright by Nemanja
like image 145
SLaks Avatar answered Dec 31 '22 05:12

SLaks


You can:

@Html.Raw(String.Format("{0} © Copyright by Nemanja", DateTime.Now.Year));
like image 22
Fals Avatar answered Dec 31 '22 06:12

Fals