0

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.

7
  • 4
    This 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. Commented 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. Commented Apr 29, 2013 at 14:03
  • As @David mentioned, taking html tags can be dangerous. I would use markdownsharp instead Commented Apr 29, 2013 at 14:23
  • I want to allow only few html code not all Commented Apr 29, 2013 at 14:26
  • @Champ726337 like here? Commented Apr 29, 2013 at 14:29

2 Answers 2

3

Use @Html.Raw( [your HTML code from the database] ) in your View.

Sign up to request clarification or add additional context in comments.

2 Comments

@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.
Thank QQping I got my answer'if(str.Contains("<b>")){ <text> Html.Raw(str) </text> } else{ <text> str </text> }'
0

In your Razor-file:

 <b>@myHtmlFromTheDatabase</b>

2 Comments

@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...
I just take an example to explain what I want in last line

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.