I saw a couple of questions about this stuff but there is no one clear for me. I have this:

Currencies.cs

public class Currencies
{
    public WorldCurrencies.CurrencyTypes Get()
    {
        var url = "http://openexchangerates.org/api/currencies.json";
        var currencies = _download_serialized_json_data<CurrencyTypes>(url);

        return currencies;
    }

    private static T _download_serialized_json_data<T>(string url) where T : new()
    {
        using (var w = new WebClient())
        {
            var json_data = string.Empty;
            // attempt to download JSON data as a string
            try
            {
                json_data = w.DownloadString(url);
            }
            catch (Exception) { }
            // if string with JSON data is not empty, deserialize it to class and return its instance 
            var res = !string.IsNullOrEmpty(json_data) ? JsonConvert.DeserializeObject<T>(json_data) : new T();
            return res;
        }
    }
}

WebAPIController.cs

public class WebAPIController : Controller
{
    public ActionResult Converter()
    {
        WorldCurrencies.Currencies curr = new WorldCurrencies.Currencies();

        return View("Index", curr.Get());
    }
}

And Index.cshtml

<div class="form-group">
    <label for="fromC">From Currency</label>
    <div class="col-md-6">
        @Html.DropDownList("Prueba", Model, )
    </div>
</div>

I am trying to populate the DropDownList with the object called currencies, but I don't have a clear idea of how to implement this.

Any clues?

EDIT: This is exactly what curr.Get() returns:

    res {WorldCurrencies.CurrencyTypes} WorldCurrencies.CurrencyTypes
    AED "United Arab Emirates Dirham"   string
    AFN "Afghan Afghani"    string
    ALL "Albanian Lek"  string
    AMD "Armenian Dram" string
    ANG "Netherlands Antillean Guilder" string
    AOA "Angolan Kwanza"    string
    ARS "Argentine Peso"    string
    AUD "Australian Dollar" string
    AWG "Aruban Florin" string
    AZN "Azerbaijani Manat" string
    BAM "Bosnia-Herzegovina Convertible Mark"   string
    BBD "Barbadian Dollar"  string
    BDT "Bangladeshi Taka"  string
    BGN "Bulgarian Lev" string
    ...

Related posts

Recent Viewed