misagh01
misagh01

Reputation: 11

"br" html tag in razor view does not break line (ASP.Net MVC)

I am new to work with Asp.Net MVC 4, I have a problem with <br> tag in a razor view,

This markup is in my index.cshtml view file:

@model List<MvcApplication2.Models.Product>

@{
    ViewBag.Title = "Index";
    var number = 12;
    var data = "some text...";
    <h2>line1: @data</h2>

    @:line-2: @data <‪br />
    <text>line-3:</text> @data
}

site@(data)
<‪br />
@@name
<‪br />
@(number / 10)
<‪br />
First product: @Model.First().Name 
<‪br />
@if (@number > 10)
{
    <span>@data</span>
}
else
{
    <text>Plain Text</text>
}
<‪br />
@foreach (var item in Model)
{
    <li>@item.Name, [email protected] </li>
}

@*
    A Razor Comment
*@

<‪br />
@("First product: " + Model.First().Name)
<‪br />
<img src="@(number).jpg" />

and my web site display this:

http://s1.img7.ir/jtp6q.jpg

Why?! Please help...

Upvotes: 1

Views: 3714

Answers (2)

sonicbabbler
sonicbabbler

Reputation: 851

In the cshtml try

@Html.Raw(data)

@Html.Raw(Model.myvar)

Upvotes: 2

Eric J.
Eric J.

Reputation: 150108

At that point, Razor things the <br /> is intended to be literal text. You can place it back in HTML syntax mode using <text> as you have attempted, but include the <br />

@:line-2: @data <text><‪br />
line-3:</text> @data

Upvotes: 0

Related Questions