Tripping
Tripping

Reputation: 919

preserving line spaces in asp .net not working

I am doing this to replace whitespaces and line breaks. The whitespaces part works however the line break does not.

It works if I removed the tags < > from the br. The line breaks in that case does get replaced by 'br'

I am using Antixss and sanitize.GetSafeHtmlFragment?

Is that causing a problem?

Upvotes: 0

Views: 269

Answers (2)

paulsm4
paulsm4

Reputation: 121609

This might work:

http://wpl.codeplex.com/workitem/14053

AntiXss.GetSafeHtmlFragment(strMessage.Replace(ControlChars.Lf.ToString(),"<br>"))

Where strMessage is the string with newlines you're calling AntiXss on.

This might also help:

Upvotes: 1

Graham.Fraser
Graham.Fraser

Reputation: 389

Maybe a little code....and a description of your current problem

Sounds like your doing this to a models field. In an edit or create view is this correct? if you are using texteditorfor(model => model.property) and the property is of type string then the line breaks will automatically be removed.

If it is a validation error due the HTML it should indicate that on the error page. If this is the case then in the model you must allow html with the [AllowHtml] attribute to the property. you must include system.mvc

Upvotes: 0

Related Questions