contactmatt
contactmatt

Reputation: 18600

MVC 3 - Additional View Data not appearing in Editor For template

In my view, I have a statement like this:

<li>@Html.EditorFor(model => model.SomeEnum, "Enum", new { ShowDefaultText = false })</li>

I have a Enum (SomeEnum) and I have a editor for template for enums. In my editor for template I'm trying to check the ViewData object for the anonymous class I passed it. According to he Html.EditorFor documentation, the third parameter is additional view data that will be with the ViewDataDictionary object.

However, in my template when looking at the ViewData class, I don't see the anonymous class/property in it. Am I doing something wrong, am I looking at the wrong object in my editor for template?

Upvotes: 8

Views: 4791

Answers (1)

Manas
Manas

Reputation: 2542

Use the following ViewData syntax

@{
    var boolValue = Convert.ToBoolean(ViewData["ShowDefaultText"]);
 }

 @if (!boolValue)
 {
     ...............
 }

Upvotes: 9

Related Questions