I am taking HTML as input from a page using Tinymce(Rich Text editor), and saving input to SQL server , While retrieving the data form database and passing it to view ,all html tags and content are showing as plain text.
I am using asp.net core MVC.
This is where you would want to use Html.Raw()
Html.Raw() with render the HTML string you pass to it as markup on the page.
Related
I am currently using ckeditor in my Django project.
setData() in inserting the text as raw html content. Any suggestion how to convert that raw HTML to rich text when setData() us used.
Follwing command is used by me.
CKEDITOR.instances.editor1.setData( "<%- data.description %>" );
Met similar problem in Flask project. In my case, raw HTML tags were transfer to HTML entities, for example, "< p >" is transfer to "<p>", thus the setData did not consider them as HTML tags.
I think you should check the source code of your web page, and to see what is in the setData().
For Flask, the following answer solved my problem:
Passing HTML to template using Flask/Jinja2
So, I have a wordpress like website in ASP.Net MVC 5, where I can create website for my customers. Now one of the customer's website needed a text box to add a html content. So, I added [AllowHTML] for that text box, so I am able to successfully save textbox content to DB. Now my question is how to render in front end. I mean I have a model property as
public string htmlcontent {get;set;}
and the value I am getting from Database is
<p>abc</p>.
Now what is the best way to render it in my cshtml file. If I do something like
#Model.htmlcontent
My output is simply <p>abc</p> as Plain TEXT But I want the DOM to understand the html content and attributes and render it accordingly.
You need to tell the razor engine not to escape your string using Html.Raw:
#Html.Raw(Model.htmlcontent)
I am working on a SpringBoot based MVC application which uses mongoDB to store the data. I am using thymeleaf as the template engine. In one of the scenarios, the user needs to fill a form which is then displayed on some view.
The problem I am facing is that the user can use html tags to format the data while writing in the textArea of the form (code snippets, tabular format etc). But when I am displaying that text, the html is not being parsed and is displayed as is.
For Ex: <b>String</b> should be displayed as String but is being displayed as <b>String</b> only. When I check the source code of the page, the html tags are displayed as encoded i.e. < is showing as < ; etc and hence the parsing is not happening.
Can someone please help
You can output unescaped text with th:utext. From the official turorial
If we want Thymeleaf to respect our XHTML tags and not escape them, we will have to use a different attribute: th:utext (for “unescaped text”):
<p th:utext="#{home.welcome}">Welcome to our grocery store!</p>
The tutorial assumes that home.welcome is a string with html-tags:
home.welcome=Welcome to our <b>fantastic</b> grocery store!.
It goes without saying that this needs very careful validation so that only safe (whatever safe is for the particular use case) HTML is stored into the database (and no possibly malicious code like <script/> tags).
In a Winforms application, I have a datatable in which one of its columns contain HTML string. I want to render the whole datatable contents on the form or in HTML where the inner HTML contents should also get rendered.
I am using C# to do this. The reason I want the HTML is that the datatable contains a report and the inner HTML contains links to images.
Can someone please help?
I cannot tell what language you're using but you'll need to HTML encode the HTML string from the datatable. Most languages will contain a method for this that takes a string as a parameter.
Why do you want to put HTML in a windows application? Do you have an HTML Editor?
With regards to web, the normal procedure would be to store the data, in a normal table, and when you load you place the HTML in a <div>. If you put runat="server" in the div, you can set the innerhtml attribute from the server side.
I have a MVC3 web project that I am trying to display text from an xml doc in the form area of one of my views.
I would like the xml to be displayed with color coding and pretty print indenting like the xml text that is displayed when you open an xml file using IE.
Currenty I am using the #Html.Display("xmlfiletext").
The text is displayed as mono color with no new lines or carriage returns.
There are lots of syntax highlighting plugins that allow you to achieve that. Google prettify is just one example.