0

I've got problem with this line:

<div class="TrescPotwierdzTresc">@Model.Article</div>

The problem is with "br" tag inside @Model.Article wont work. I can see this tag after page load, but text is still in the same line. WHen i do something like this:

<div class="TrescPotwierdzTresc">@Model.Tresc br @Model.Tresc</div>

The br tag between "@Model.Tresc" elements work fine. Do You have any idea why is that happening ?

Max Al Farakh
  • 4,386
  • 4
  • 29
  • 56
Shagohad
  • 361
  • 1
  • 10
  • 20
  • You need to show us what's inside @Model.Article and also tell us what templating system you're using. – Oin Jun 11 '14 at 08:02
  • It is Razor obviously – Max Al Farakh Jun 11 '14 at 08:03
  • Inside @Model.Article is "public string Article { get; set; }", and to bind this string i'am using simple ado.net code: SqlDataReader rdr = com.ExecuteReader(); while (rdr.Read()) { model.Article = rdr["Article"].ToString(); model.Autor = rdr["Autor"].ToString(); model.Data = rdr["Data"].ToString(); model.zdjecieLink = rdr["LinkZdjecie"].ToString(); model.id = Convert.ToInt32(rdr["ID"].ToString()); } } – Shagohad Jun 11 '14 at 08:06

1 Answers1

2

Try this:

<div class="TrescPotwierdzTresc">@Html.Raw(Model.Article)</div>

Html.Raw returns markup that is not HTML encoded.

Max Al Farakh
  • 4,386
  • 4
  • 29
  • 56
  • Ok, thanks for eplain. I will accept answer soon, Thank You for help, it works fine ! – Shagohad Jun 11 '14 at 08:09
  • 1
    By default ASP.NET encodes all HTML entities due to security reasons. So your `
    ` tags look like `<br>`. `Html.Raw` decodes them so that browsers can render them correctly.
    – Max Al Farakh Jun 11 '14 at 08:11
  • @Null Reference, please add your warning as a comment under the answer. – user1725145 Jun 11 '14 at 11:41
  • Caution: Html.Raw should be used with caution since it may lead to [cross site scripting] (http://stackoverflow.com/a/7751180/3186681). As per [MSDN](http://msdn.microsoft.com/en-us/library/gg568896%28v=vs.99%29.aspx)Html.Raw() is a Medium trust for the immediate caller. This member can be used by partially trusted code. – ManirajSS Jun 11 '14 at 11:44