0

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!!

2
  • Why insert your code as screenshots when SO has syntax highlighting? Commented Sep 22, 2013 at 9:16
  • can you make sure that it really doesn't print anything into your html markup? Just examine the html source of the output. Commented Sep 22, 2013 at 9:17

1 Answer 1

1

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>
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.