Solved

HTML displaying rich text (html format)

Posted on 2014-12-24
13
25 Views
Last Modified: 2016-04-20
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 --
0
Comment
Question by:chuang4630
  • 6
  • 4
13 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 40516751
i am lost :) screenshots please...
0
 
LVL 1

Author Comment

by:chuang4630
ID: 40516761
I have attached the screen capture
html01.PNG
0
 
LVL 1

Author Comment

by:chuang4630
ID: 40516763
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>
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 1

Author Comment

by:chuang4630
ID: 40516767
Here is the screen shots of the rendered html (from Inspect element)
html02.PNG
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40516769
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

0
 
LVL 12

Expert Comment

by:FarWest
ID: 40516770
did you try to use surround it with <pre> tag
0
 
LVL 1

Author Comment

by:chuang4630
ID: 40516780
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?
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40516783
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...
0
 
LVL 1

Author Comment

by:chuang4630
ID: 40516810
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?
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40516814
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...
0
 
LVL 1

Accepted Solution

by:
chuang4630 earned 0 total points
ID: 40516835
I got it.

@Html.Raw(@item.Description)
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question