views:

33

answers:

2

I have HelpBoxes in my DB. those are messages people get on the site. each message has a receiver. either it's an organisation or a user, or both.

I have this Enum

    public enum Ontvangers {
        All = 'A',
        Organisation = 'I',
        User = 'D'
    }

now in my index view

    public ActionResult Index(string schooljaarparam) {
        var boxes = _db.HelpBoxes.Where(q => q.Schooljaar.Sch_Schooljaar == schooljaarparam);
        return View(boxes);
    }

and

<% foreach (var item in Model) { %>

    <tr>
        <td>
            <%: Html.ActionLink("Edit", "Edit", new { id=item.hlpb_ID }) %> |
            <%: Html.ActionLink("Details", "Details", new { id=item.hlpb_ID })%> |
            <%: Html.ActionLink("Delete", "Delete", new { id=item.hlpb_ID })%>
        </td>
        <td>
            <%: item.hlpb_Titel %>
        </td>
        <td>
            <%: item.hlpb_Schooljaar %>
        </td>
        <td>
            <%: item.hlpb_Ontvanger %>
        </td>
        <td>
            <%: item.SiteMap.Title %>
        </td>
    </tr>

<% } %>

I get only to see the A, I or D. now I want to show User, Organisation or All

How do I get that value there? I probably need to use an extension but I am not very familiar with Enum's. Some advice would be appreciated.

edit:

it works, but it aint pretty :) I would like to put it in a helper, but how...

        <td>
            <%: Enum.GetName(typeof(MVC2_NASTEST.Controllers.HelpBoxController.Ontvangers),(int)char.Parse(item.hlpb_Ontvanger.Trim())) %>
        </td>
+1  A: 

Try this:

Enum.GetName(typeof(Ontvangers), (int)'A');
adrift
+1  A: 

You can get enum name from value:

Enum.GetName(typeof(Ontvangers), (Ontvangers)'I')
Branimir
and where would i put that code?
Stefanvds
Can you convert this field to string in model or controler? The other way is to build your own Html Helper method.http://www.asp.net/mvc/tutorials/creating-custom-html-helpers-cs
Branimir
i want to make my own helper, but i have no idea how to send my enum with the helper...
Stefanvds