Link to home
Start Free TrialLog in
Avatar of chuang4630
chuang4630

asked on

HTML displaying rich text (html format)

I have a HTML5 file such as :

<div>Value= @item.Description</div>
<div>Hardcode=<p><strong>First Item of Group A-0 description</strong></p><ul><li>First line</li><li>Second line</li></ul><p>-- END --</p><p>
</div>
The value of @item.Description is: =<p><strong>First Item of Group A-0 description</strong></p><ul><li>First line</li><li>Second line</li></ul><p>-- END --</p><p>

The output:
Value=<p><strong>First Item of Group A-0 description</strong></p><ul><li>First line</li><li>Second line</li></ul><p>-- END --</p><p>

Hardcode=
First Item of Group A-0 description

First line
Second line
-- END --

How do I resolve this to display:

Value=
First Item of Group A-0 description

First line
Second line
-- END --
Avatar of HainKurt
HainKurt
Flag of Canada image

i am lost :) screenshots please...
Avatar of chuang4630
chuang4630

ASKER

I have attached the screen capture
html01.PNG
Here is the code:
                                        <div>Value=@Item.Description</div>
                                       
                                        <div>Hardcode=<p><strong>First Item of Group A-0 description</strong></p><ul><li>First line</li><li>Second line</li></ul><p>-- END --</p><p></div>
Here is the screen shots of the rendered html (from Inspect element)
html02.PNG
shooting in the dark :)

<div>
Value= 
<p><strong>First Item of Group A-0 description</strong></p>
<ul><li>First line</li><li>Second line</li></ul>
<p>-- END --</p>
</div>

Open in new window

did you try to use surround it with <pre> tag
I have tried.
<pre>@Item.Description</pre>.

But there is no change.  Basically, the html5 treats the value of @Item.Description as string, so it puts " " on the output (see it in the screenshots). What it should do is to display the innerHTML.  But I do not know how to do it in the HTML. This is a small snippet in the @foreach loop. I would like to do it in the HTML, so it is readable.

How do I force browser to treat the value of @Item.Description as HTML markup, NOT the string?
i dont see what you post here...

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body>

<div>Value= @item.Description</div>
<div>Hardcode=<p><strong>First Item of Group A-0 description</strong></p><ul><li>First line</li><li>Second line</li></ul><p>-- END --</p><p>
</div>
The value of @item.Description is: =<p><strong>First Item of Group A-0 description</strong></p><ul><li>First line</li><li>Second line</li></ul><p>-- END --</p><p>

</body>
</html>

Open in new window


here is html5 file... save it to html file and open, you will not see what you posted...

post your code, not rendered html, or post view source, not from inspector...
I am working on the MVC project. So the @item.Description is the value from the model. It is a html markup.
However, when I display it, it shows the markup language, instead of the rendered html:

<div>Value= @item.Description</div>

For example,  <li>First line</li>.  It display as straight string "<li>First line</li>". What I want is the rendered version of the it.

If you look at the "view source", you will see :
<div> "<li>First line</li>"</div>

Pay attention to the quotation mark, that forces the browser to treat it as a string. That is wrong. How do I fix it?
even this one

<div>"<li>First line</li>"</div>

looks ok in browser! like this:

"
* First Line"

Open in new window


or this

"
* First Line
"

Open in new window

please post full html rendered... and/or code that produces it...
ASKER CERTIFIED SOLUTION
Avatar of chuang4630
chuang4630

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial