Let me explain in detail There is textarea in form. On submitting form,the text of textarea get stored in database. While display those texts from database I want to execute basic html code like <b><i><u>...etc For example:-If user entered "<b>hello</b>" in textarea.Then this word "hello" will display in bold letters.
Asked
Active
Viewed 851 times
0
-
4This is a very dangerous thing to do. The user could also enter client-side scripting and your website would serve that scripting to its users as thought it came from you. – David Apr 29 '13 at 14:03
-
If you dump that text directly into a div, does that not work? EDIT: This is of course with the warning that @David has given above. – Ravi Y Apr 29 '13 at 14:03
-
As @David mentioned, taking html tags can be dangerous. I would use [markdownsharp](https://code.google.com/p/markdownsharp/) instead – I4V Apr 29 '13 at 14:23
-
I want to allow only few html code not all – Sameer Carpenter Apr 29 '13 at 14:26
-
@Champ726337 like [here](http://stackoverflow.com/a/1732454/932418)? – I4V Apr 29 '13 at 14:29
-
No I want also to execute tags like – Sameer Carpenter Apr 29 '13 at 14:35
-
@Champ726337: The internet at large does not want tags like ` – David Apr 29 '13 at 15:42
2 Answers
3
Use @Html.Raw( [your HTML code from the database] )
in your View.

QQping
- 1,370
- 1
- 13
- 26
-
@Champ726337: It's pretty much all or nothing with HTML. You could strip anything between <> characters that doesn't match those tags, if you want to dive into the magical lands of Regex. – Jeff Apr 29 '13 at 14:10
-
Thank QQping I got my answer'if(str.Contains("")){
Html.Raw(str) } else{str }' – Sameer Carpenter Apr 29 '13 at 14:41
0
In your Razor-file:
<b>@myHtmlFromTheDatabase</b>

Martin Mulder
- 12,642
- 3
- 25
- 54
-
@Champ726337: In that case: clearify your question. Or at least: ask a question. I had the impression you that the textarea and database part were already done and you could not fix the last step... – Martin Mulder Apr 29 '13 at 14:23
-