pubi
pubi

Reputation: 13

ASPNET MVC formatting string in View

I want to make an MVC View, which shows a string.

The string contains whitespaces (" ", "/t", "/n") and I want to show it in format defined in string.

My problem is, that if I return the string as ViewBag message, all of these whitespaces are lost. Is there any solution to resolve this problem?

Upvotes: 0

Views: 88

Answers (3)

AthibaN
AthibaN

Reputation: 2087

A work around, replace \t with &nbsp and \n with <br/> and you could use,

@Html.Raw(ViewBag.Something)

Upvotes: 1

You have two options to achieve this.

use pre htnml tag

or

you have to hard code the space chars into   non-breaking white spaces.

hope it will help you to some extent.

Upvotes: 0

Brian Mains
Brian Mains

Reputation: 50728

Your issue is a web one where the browser ignores extraneous space. You need to convert all space characters to   if you want to retain the number of spaces.

Upvotes: 0

Related Questions