asp.net mvc - Enum object not found with razor -


the object 'yogaspaceaccommodation' i'm using type in getenumdescription seems brown , not found. or here isn't correct in terms of syntax.

<div id="accomodationtypeselector">    <select class="form-control" id="spaceaccommodation" name="yogaspaceaccommodation">      <option id="default">0</option>      @{           var accomodationvalues = enum.getvalues(typeof(yogaspaceaccommodation));           foreach (var value in accomodationvalues)           {                var index = (int)@value; var description = @enumhelper.getenumdescription                         <yogaspaceaccommodation>(@index.tostring());           }        }    </select>  </div>

enumdescription looks this

public static string getenumdescription<t>(string value)     {         type type = typeof(t);         var name = enum.getnames(type).where(f => f.equals(value, stringcomparison.currentcultureignorecase)).select(d => d).firstordefault();          if (name == null)         {             return string.empty;         }         var field = type.getfield(name);         var customattribute = field.getcustomattributes(typeof(descriptionattribute), false);         return customattribute.length > 0 ? ((descriptionattribute)customattribute[0]).description : name;     } 

find out namespace enum in , add using declaration @ top of view. namespace myapp.data.enums add:

@using myapp.data.enums 

to top of view @model declaration. can add namespace through web.config located in views folder:

<system.web.webpages.razor>   <pages pagebasetype="system.web.mvc.webviewpage">     <namespaces>       <add namespace="myapp.data.enums" />     </namespaces>   </pages> </system.web.webpages.razor> 

note when make these changes have close , reopen views intellisense catch up. may need namespace of helper functions using.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -