1

I have an webapplication written in MVC4/Razor. And I try to add a next line in my view dynamically. How can I do that?

I have tried this with "<br />" and "&10;&13;" too.

In the controller

exmaple.References = anExample.References.Replace(";", ";/r/n");
exmaple.Methods.AddRange(anExample.Methods);
exampleList.Add(example);

In the view

      <p>
                <span class="label">@Html.DisplayNameFor(model => model.Methods)</span>
                @{ 
                    foreach (var method in item.Methods)
                    {
                        <span>@Html.DisplayFor(modelItem => method)</span>
                    }
                }
            </p>

Result:

References using System;/r/n using System.ComponentModel;/r/n

user1531040
  • 2,143
  • 6
  • 28
  • 48
  • http://stackoverflow.com/questions/5032097/asp-net-mvc-convert-n-new-line-to-html-breaks maybe – artm Nov 12 '14 at 11:30

1 Answers1

0

I'd suggest using Environment.NewLine as a line break in the model, but whatever you want works. In the view:

 foreach(var method in item.Methods){
       Html.Raw(method.Replace("[whatever line break character you have]", "<br />"))
 }
sebbzzz
  • 471
  • 4
  • 14