Alex Rivera | Logout

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

Asked 2012-02-24T23:11:32.197
8

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?

Edit
Report

1 Answer

9

Use the following ViewData syntax

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

 @if (!boolValue)
 {
     ...............
 }
answered 2012-02-25T02:15:51.797

Your Answer