我一直在努力尝试在最近3天内工作,您如何将数据从api控制器传递到mvc控制器并使用数据填充selectlistitem。API控制器将数据传递给mvc控制器
我已经看到很多从网页调用api的例子,这些例子都很好,但是如果用户禁用了javascript,它将不会显示数据。
因此,任何有关此示例的帮助将不胜感激。
我的代码是:
web.api
public IEnumerable<DisplayCurrencyInDDL> GetCurrencyForDDL()
{
var s = _ICurr.InsetCurrencyIntoDataBase();
return s.AsEnumerable();
}
MVC控制器
WebClient wc = new WebClient();
var s = wc.DownloadString("http://localhost:50687/api/Currency");
我如何从变种S(货币和currencyid)的值成selectlistitem。
感谢 乔治
edit data returned as: [ { "strCountry": "Afghan Afghani", "strCountryCode": "AFN" }, { "strCountry": "Albanian Lek", "strCountryCode": "ALL" }, { "strCountry": "Algerian Dinar", "strCountryCode": "DZD" }, { "strCountry": "Andorra Euro1",
什么是var s的格式?你可以在这里发布样本吗? – ryadavilli
嗨@ryadavilli示例代码[{“strCountry”:“阿富汗阿富汗人”,“strCountryCode”:“AFN”},{“strCountry”:“阿尔巴尼亚列克”,“strCountryCode”:“ALL”},{“strCountry”: “阿尔及利亚第纳尔”,“strCountryCode”:“DZD”},{“strCountry”:“安道尔欧元”, – CareerChange