A
A
Alex2014-12-02 00:16:40
JavaScript
Alex, 2014-12-02 00:16:40

How to keep formatting when inserting html piece from db?

Hello everyone ... I use FroalaEditor in the project, I added a custom button to it so that I could insert code. Here's what happens:
3d2aa38ce91f4502862249b73e6c1621.png
I send the following line to the database with all the tags:

<pre class="fr-tag">public ActionResult Search()        {            var allQuestions = questionRepository.GetAllQuestionsInfo().ToList();            LuceneSearchIndexer.RunIndex(allQuestions);            string title = "Test";            var result = LuceneSearch.Search("Title", title);            List SearchLit = new List();            foreach (var k in result)            {                var q = questionRepository.GetQuestionById(k.Id);                SearchLit.Add(q);            }            return View(result);        }<br></pre>

and through @Html.Raw I output the string, but it loses formatting .. and it turns out:
fd3e19f9ff69493d8773d0f5c5712ad5.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JackBoner, 2014-12-02
@JackBoner

yes, there is simply no line break as far as I know, in HTML the br
tag is responsible for the new line break, so convert the DB break character to html like this:

@Html.Raw(ViewBag.Text.Replace(Environment.NewLine, "<br>"));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question