Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 770
contactmatt Avatar asked Feb 24 '12 23:02

contactmatt


1 Answers

Use the following ViewData syntax

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

 @if (!boolValue)
 {
     ...............
 }
like image 113
Manas Avatar answered Sep 27 '22 17:09

Manas