MVC3 putting a newline in ViewBag text

14,289

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.

Share:
14,289
MikeTWebb
Author by

MikeTWebb

I am a C# .Net/SQL/Oracle/Web developer. Also experienced in Business Analysis and Customer Interaction.

Updated on July 28, 2022

Comments

  • MikeTWebb
    MikeTWebb almost 2 years

    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?

  • MikeTWebb
    MikeTWebb about 12 years
    @post....this worked but, again, decided to keep the markup language in the View and not the controller. Thanks
  • DaFois
    DaFois over 4 years
    Could you please add some explanation to the answer?