0

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?

3 Answers 3

1

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

@Html.Raw(ViewBag.Something)
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

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.

Comments

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.