Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC3 putting a newline in ViewBag text

Tags:

I have an MVC3 C#.Net web app. I am looping through a DataTable. Some rows are importing OK, some are not. I am wanting to send a list of errors back to the view in a list format. I am assigning the following text to a ViewBag property

Input error on Row(1) Cell(3) Input string was not in a correct format.<br/> Input error on Row(4) Cell(3) Input string was not in a correct format.<br/>

I was hoping the br would write a line break in the HTML. It does not. I want the error message to look like this

Input error on Row(1) Cell(3) Input string was not in a correct format.
Input error on Row(4) Cell(3) Input string was not in a correct format.

Any ideas?

like image 517
MikeTWebb Avatar asked Feb 08 '12 17:02

MikeTWebb


1 Answers

When you throw into your view, use

@Html.Raw(ViewBag.Test)

instead of

@ViewBag.Test

That will signify to the compiler that string is html and does not need to be encoded as such.

like image 170
devstruck Avatar answered Nov 09 '22 04:11

devstruck