locked
retrieve articles from database without the html tags RRS feed

  • Question

  • User1519602350 posted

    Hello, How to retrieve articles from database without the html tags. I am using cke editor the articles saved with html editor. How to reterive without html tags using C# Razor formatting or sql?

    @item.articleContent
    
    Wednesday, July 24, 2013 12:13 PM

Answers

  • User-1980594115 posted

    Are you wanting to display the variable like this:

    @{
        @Html.Raw(@item.articleContent)
    }

    or do you want to get rid of the HTML tags like this:

    @using System.Text.RegularExpressions;
    
    @{
        var result = Regex.Replace(item.articleContent,@"<(.|\n)*?>",string.Empty); 
    }
    



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2013 12:39 PM
  • User-1980594115 posted

    Make sure that you place @using System.Text.RegularExpressions;  at the top of the page before any other coding.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2013 12:45 PM

All replies

  • User1308270069 posted
    var ac = new HtmlString(htmlText);

    and now you can use "ac" in your HTML

    Wednesday, July 24, 2013 12:21 PM
  • User1519602350 posted

    I am looking for reterive data without html tags.. So it should be print as normal text.

    Wednesday, July 24, 2013 12:23 PM
  • User1308270069 posted

    when you are using an Html Text Editor, your text contains Html tags. at least <p> tag

    Wednesday, July 24, 2013 12:26 PM
  • User-1225287840 posted

    Just create a generic SQL function to handle this,

    http://stackoverflow.com/questions/457701/best-way-to-strip-html-tags-from-a-string-in-sql-server 

    Wednesday, July 24, 2013 12:31 PM
  • User1519602350 posted

    Take an example. Below content stored in database with html tags. What i want here is while reteriving the content all html to be removed and print it as normal text in cshtml page. How to achive this using cshtml or sql?

    <div class='row'><div class='large-12 columns'><h2 class='has-line'>Main Heading?</h2><p>Donec augue turpis, tempor id pulvinar eget, cursus eget ante. Proin sit amet nibh sem. Sed tortor arcu, egestas eu molestie in, lacinia luctus justo. Suspendisse semper, justo eget hendrerit viverra, mauris ligula gravida lorem, vitae mollis nisi nisl sed velit.</p>

    Wednesday, July 24, 2013 12:32 PM
  • User-1980594115 posted

    Are you wanting to display the variable like this:

    @{
        @Html.Raw(@item.articleContent)
    }

    or do you want to get rid of the HTML tags like this:

    @using System.Text.RegularExpressions;
    
    @{
        var result = Regex.Replace(item.articleContent,@"<(.|\n)*?>",string.Empty); 
    }
    



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2013 12:39 PM
  • User1519602350 posted

    Yes i want to get rid of html tags. var result = Regex.Replace(item.Content,@"<(.|\n)*?>",string.Empty);. 

    But i am getting an below error.

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0103: The name 'Regex' does not exist in the current context

    Wednesday, July 24, 2013 12:43 PM
  • User-1980594115 posted

    Make sure that you place @using System.Text.RegularExpressions;  at the top of the page before any other coding.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2013 12:45 PM
  • User1519602350 posted

    Thanks dblaire

    Wednesday, July 24, 2013 12:47 PM