I'm using ASP.NET MVC4 C# and I'm facing a problem with displaying an array in my View:
I'd like to display a number of error messages from my controller to the view, but so far, the content of only 1 array is displayed...
Only the data in "ViewData["mededelingen"] is displayed. The data in ViewData["warnings"] is not displayed, despite the same code.
Below is the code of the view:
When I debugged, I have noticed that the ViewData["warnings"] is not empty, as shown in the next screenshot:
However, it does not display the contents on my HTML page.
Below is the output:
As you can see, only the items in red (mededelingen) are displayed, the items in yellow (warnings) are not.
Below is the code of the controller:
Obviously I'm doing something wrong, but I can't figure out what exactly... Any help?
Thanks in advance!!
DisplayName
gets the display attribute of the model property represented by the string that's passed to it. Since your string is just a sentence, that doesn't make sense. Why are you using DisplayName
at all?
Just do:
@foreach (var counter2 in (ViewData["warnings"] as List<string>))
{
<td>@counter2</td>
}