Use string[]
to store your errors. Thus, they are a well-formed and excellent set of errors instead of one long line.
In your controller, initializing the ViewBag
property:
ViewBag.Errors = new string[] { "First error", "Second error" };
Your view displays the following errors:
@foreach (string error in ViewBag.Errors) { @Html.Label(error) <br /> }
Separation of problems
You should not handle markup in your controller (i.e. line breaks or any other DOM elements). Presentation should be processed only by View. Therefore, it would be better to pass string[]
.
user596075
source share