按名称订购货币代码

时间:2015-10-06 11:27:21

标签: c# asp.net-mvc

如何按名称订购我的货币代码。在数据库中,我有Id和Code(名称),目前它们是按Id排序的。我想按名称ASC订购。 Down是我在ASP.NET中的C#代码

namespace Portal.Framework.Mvc.ViewDataPreparers
{
  public class CurrenciesCodesPreparer : ActionFilterAttribute, IDataPreparer<Currency>
  {
    public IList<Currency> GetDataItems()
    {
      return DefaultContainerReference.Resolve<IGlobalizationService>().GetAllCurrencies().CurrencyList;
    }

    public static string ViewDataKey { get { return "CurrenciesCodes"; } }

    public override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
    {
      base.OnActionExecuting(filterContext);
      filterContext.Controller.ViewData[ViewDataKey] = GetDataItems().ToSelectableList(true, Resources.Default_All, null, null, "Id", "Code");
    }
  }
}

1 个答案:

答案 0 :(得分:0)

这很简单。

var currency = getallCurrency();
var sortByName = currency.OrderBy(x=>x.CurrenyName);

你可以这样做。