Display string as html in asp.net mvc view

后端 未结 5 1730
北恋
北恋 2020-12-01 04:22

I have a controller which generate string containing html markups.Now when I am displaying it on views, it is displayed as simple string containing all tags. I tried to u

5条回答
  •  失恋的感觉
    2020-12-01 04:42

    I had a similar problem recently, and google landed me here, so I put this answer here in case others land here as well, for completeness.

    I noticed that when I had badly formatted html, I was actually having all my html tags stripped out, with just the non-tag content remaining. I particularly had a table with a missing opening table tag, and then all my html tags from the entire string where ripped out completely.

    So, if the above doesn't work, and you're still scratching your head, then also check you html for being valid.

    I notice even after I got it working, MVC was adding tbody tags where I had none. This tells me there is clean up happening (MVC 5), and that when it can't happen, it strips out all/some tags.

提交回复
热议问题