0

I have following controller

    public ActionResult Dashboard()
    {
        return View(db.AB_Product_vs_Field.ToList());
    }

I'm getting following view for above controller method which is containing with HTML tags(actually those field's values are saved in database with HTML tags)

enter image description here

How can I remove these html tags and show just the plain text.what's the least and simple effort for this

9
  • @Arvaan But it might also open up for script injection! Commented Nov 20, 2015 at 7:04
  • Ok. My bad. He just wants to remove tags. I was thinking he wants to apply HTML tags effect also Commented Nov 20, 2015 at 7:05
  • Send the view to simulate it. Commented Nov 20, 2015 at 7:05
  • Do you mean you want to display only "Product Title" in the 3rd column? Commented Nov 20, 2015 at 7:11
  • The best way to handle this is to not save the HTML-code in the database. Is that possible for you? Commented Nov 20, 2015 at 7:11

3 Answers 3

1

Simply make use of @Html.Raw() that returns markup that is not HTML encoded.

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

1 Comment

I think it will also give effect of HTML Tag, and he does't want it. He just want to remove HTML tags and want specific Text decorated by tag
1

This will remove html tags

@Regex.Replace(your_variable, @"<[^>]+>", "")

3 Comments

where should I place this ?
into your view or controller, its depend on your code
0

Regex is the best option to do it.

Let us example:-

If you want to remove any HTML tags:-

String OnlyString = someString.replaceAll("<[^>]*>", "");

If you want to remove any specific HTML tag:-

String removedSpecific = someString.replaceAll("(?i)&lt;td[^>]*>", "");

Hope above example will solve your issue. :)

2 Comments

could you please let me know where should I insert this ? controller method or viewpage ?
It's a C# code, you can add this in controller, if you want same conversion in view, Please make some ajax like call, and from javascript you can . :)

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.