Question

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:

enter image description here

When I debugged, I have noticed that the ViewData["warnings"] is not empty, as shown in the next screenshot:

enter image description here

However, it does not display the contents on my HTML page.

Below is the output:

enter image description here

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:

enter image description here

Obviously I'm doing something wrong, but I can't figure out what exactly... Any help?

Thanks in advance!!

Était-ce utile?

La solution

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>
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top