How to show new line from mvc4 text area?

I use mvc4 and I use the Arabic language in the view (lang = "ar"), the text for saving the current code in the sql table is for example: مرحبامرحبا is stored in the sql table, but when it is read from the sql table, the output

مرحبا <\br> مرحبا 

I want the result to be like this:

مرحبا

مرحبا

 modelcar.CarDescription = modelcar.CarDescription .Replace(System.Environment.NewLine, "<br />"); AdvertFunObj.Add(modelcar); 

view

 <br /> <hr /><br /> الاضافات<span class="blue"><%:Model.CarDescription %></span><br /> 
+4
source share
2 answers

You need to use Html.Raw to output the HTML in your view, otherwise it will just be treated as a string. Try the following:

 الاضافات<span class="blue"><%:Html.Raw(Model.CarDescription) %></span><br /> 

Edit:. Although, as commentators note, make sure that you have not disabled RequestValidation , otherwise it will be vulnerable to XSS attacks (what if you really allow people to add cars).

+3
source

If you used a razor viewer mechanism, the way to not encode HTML code would be to write:

 <hr /><br /> الاضافات<span class="blue">@Html.Raw(Model.CarDescription)</span><br /> 

Maybe try

 <hr /><br /> الاضافات<span class="blue"><%: Html.Raw(Model.CarDescription %></span><br /> 
0
source

All Articles