How to add line break in Get() at Web API REST

public string Get()
{
     return "a <br /> b";
}

How to add a line break to a string that will be used in Get() at Web API ASP.Net?

I tried some solutions below, but it didn't give me a line break.

return " a \n b";
return "a \r\n b";
return "a" + Environment.Newline (not sure about the spelling of newline) + "b";
return "a <br/> b";
return "a <br /> b";
return "a <br> b";

Just to be sure, its not HttpRequest that I'm trying to get, it's a string. Please and thank you.

Code

enter image description here

Result enter image description here

Upvotes: 0

Views: 4309

Answers (1)

NajiMakhoul
NajiMakhoul

Reputation: 1716

"a \n b" and Environment.NewLine will give you new line break, I tested it with chrome.

result:

enter image description here

if you want to return HTML string text using beak with <br /> you need to return it as ContentResult

public ContentResult Get()
{
    return new ContentResult
    {
        ContentType = "text/html",
        Content = "a <br /> b"
    };

}

with HTML result:

enter image description here

Upvotes: 2

Related Questions