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.
-
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– David2013-04-29 14:03:18 +00:00Commented Apr 29, 2013 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– Ravi Y2013-04-29 14:03:34 +00:00Commented Apr 29, 2013 at 14:03
-
As @David mentioned, taking html tags can be dangerous. I would use markdownsharp insteadI4V– I4V2013-04-29 14:23:40 +00:00Commented Apr 29, 2013 at 14:23
-
I want to allow only few html code not allSameer Carpenter– Sameer Carpenter2013-04-29 14:26:40 +00:00Commented Apr 29, 2013 at 14:26
-
@Champ726337 like here?I4V– I4V2013-04-29 14:29:17 +00:00Commented Apr 29, 2013 at 14:29
|
Show 2 more comments
2 Answers
Use @Html.Raw( [your HTML code from the database] ) in your View.
2 Comments
Jeff
@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.
Sameer Carpenter
Thank QQping I got my answer'if(str.Contains("<b>")){ <text> Html.Raw(str) </text> } else{ <text> str </text> }'
In your Razor-file:
<b>@myHtmlFromTheDatabase</b>
2 Comments
Martin Mulder
@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...
Sameer Carpenter
I just take an example to explain what I want in last line