-2

I have some content in my database column with html tags in it so that if I assign the column data to text of a label the whole content is presentable with line breaks and other html tags.

I have a asp.net site in which I am doing doing this and its fine and now I am trying to do the same with @html.Raw tag in MVC view but the same output is not achieved as Asp.netenter image description here

Taqi Gates
  • 87
  • 1
  • 8

1 Answers1

-2

Does your database column with this HTML in, contain br tags for those new lines or is it just stored as Carriage Returns?

If so, I think this is because Html.Raw() does not honour linebreaks/carriagereturns eg "\n".

What you could do is something like the answers in this article

@Html.Raw(message.Replace(Environment.NewLine, "<br/>"))

Ideally, you would update your existing data in your database to replace NewLine characters with br tags, so that you don't do this when rendering your view, and then modify your code that persists this data to the database so that NewLines are converted straight into br tags, or replace your text area with a HTML Editor.

Community
  • 1
  • 1
jonhoare
  • 1,279
  • 7
  • 15
  • 1
    this is data in my column -- Example:
    # include<stdio.h> # include<conio.h> main() { printf("Hello \t ") ; printf("World \n") ; printk("Welcome ") ; ------Error "printk" instead of "printf" } In the above program their is an error at 9th line of code, in the case of interpreter here above 8 lines are converted machine language and while the interpreter comes to 9th line it stop convertion and shows a message regarding the error. After correction it goes for converting 9th and 10th line of code to machine language.
    – Taqi Gates Jul 10 '15 at 14:04
  • `message.Replace("
    ", "
    ")`
    – Inspector Squirrel Jul 10 '15 at 14:07
  • Well your br's are working, but you can see in your example html that you have no br's between include<stdio.h> and # include<conio.h> therefore these must be NewLine markers in the text. Try replacing NewLine with
    like above and hopefully it should work.
    – jonhoare Jul 10 '15 at 14:09