views:

362

answers:

2

So I have this .resx file and I want its values shown in a drop down list in ASP.NET MVC (C#). Is this possible? Google couldn't help me, so I hope SO can :-)

A: 

It really depends on how you have the values saved in the RESX. Let's just say you have the values saved as a string.

App_GlobalResources/Messages.resx:

Name   |   Value
---------------------
title  |   Mr.,Mrs.,Ms.
List<SelectListItem> items = new List<SelectListItem>();
foreach (string s in Resources.Messages.title.Split(new char[] { ',' }))
{
   items.Add(new SelectListItem() { Text = s, Value = s });
}
Response.Write(Html.DropDownList("Title", items));
+3  A: 

This works for me

Html.DropDownList("ResxDropDownList",
    new SelectList(
     Resources.YourResource.ResourceManager.GetResourceSet(
      System.Globalization.CultureInfo.CurrentCulture,
      true,
      true
     ),
     "Key",
     "Value"
    )
)
n26
thanks! this works exactly as expected
jao