How to convert the data into html reading from data base - asp.net-mvc

I am developing an application in which I have used the editor so when the user submit the data the data was send to the sql server in HTML format.
<p><strong><em>fghfghfghfghfghfghfgdfxvbc</em></strong></p> <ol> <li>.
it will not converted in to html tags.
I'm using Asp.net Mvc.
The code is as follow:

When adding raw HTML to a page in ASP.NET MVC, you need to use
#Html.Raw("your html string here")

Related

how to display quilljs editor written data in Angular coming from Node API

I have data written in QuillJS Editor, when I store that data it stores the data along with the HTML tags in my database.
For Example if I right this in the editor
This is an example.
It is stored as
<p>This is an example.</p>
Now when I'm trying to display these data in my Angular front-end HTML file it shows the HTML tags along with the data enclosed between them.
<p>This is an example.</p>
How will I only show the text enclosed in the tags and not the HTML tags?
To Display data in HTML that was entered by a user using QuillJs, you have to use QuillJs editor in read mode to display that data.
<quill-editor [(ngModel)]="yourNgModel" [readOnly]="isReadOnly" [modules]="{toolbar: false}">
</quill-editor>

asp.net mvc rasor #raw does not accept <br>

I have a solution that uses asp.net web api to convert data to pdf.
I am using #Raw to display the data in a html formatted manner. But the problem is that if the json string contains the html <br> it throws an error. Once I change it manually to XHTML <br/> it works fine.
Why can't #Raw handle html breaks ? Is there a better way to handle html tags?
Description
#Raw(#Model.Description)
For security reasons, Raw method is not recommended for using - it does not encode input string. The better solution, especially when you already use Web API, would be to just return the non-formatted data, and do the html formatting on the client-side, maybe using some templates library.

Showing html data from database to front end in mvc

I have upgraded my application from asp.net to mvc4. I am using html5 and displaying data in an html table. My database column contains html tags, but it is getting rendered as a plain text. Please help.
**
> Removable hard drive carrier only (DataPort)<html><br><b><font color
> ="red"> Part 444873-001 is no longer supplied. Please order the replacement, 580620-001</font></b></br></html>
**
Above line is a sample of how my data gets displayed in the column. I want to make the html tags to be rendered as html itself.
When you render your model data, use the Html.Raw() helper to render the HTML data unencoded. Razor automatically encodes HTML inputs in order to help prevent XSS attacks on websites.
<td>#Html.Raw(Model.MyProperty)</td>

Display file (PDF/TXT) on form brought from Database in MVC ASP.NET

I want to display file on my form using MVC.
I am bringing a Byte[] array data from the Database, and using FileContentResult I am converting it into a file.I want to now display this file on my page for viewing . How can it be acheived. What code to write in my View for the same.
Assuming you're using Razor, rendering a text file can be done as simple as:
<div>
#(new System.IO.StreamReader("myFile.txt")).ReadToEnd()
</div>
For PDF files, you'll have to find a third-party component to convert to HTML.
You probably don't want to use FileContentResult, that is something generally used for providing the raw file.
In theory though there is nothing different in using any other url
<img src="#Html.ActionLink("View","Image",{id = Model.key})" />
Or you can provide that link in a pdf reference, or as a stylesheet etc.

ASP.net MVC rendering html pages

I have HTML Pages in my ASP.net MVC project. How can i render these pages with dynamic values.
Index.html
< input type="text" value=<%=Dynamic Value Here%> />
You can't since HTML files will not be parsed by the ASP.NET MVC view engine and it won't understand the server side syntax you will need to insert dynamic values. In order to do this you will need to translate your HTML files into aspx files to use the webforms view engine syntax of <%: %> or cshtml files to use the razor syntax of #. Now you will be able to insert dynamic values since the view engine will insert those values into the HTML that is returned to the browser to be rendered.

Resources