I currently have a
List<KeyValue<string, int>>
that I utilize in the View
of one of my applications. While it functions as intended, I am interested in expanding it by potentially incorporating an additional parameter/value to the KeyValue
pair.
Each pair corresponds to a specific color, which I would like to pass to the inline CSS color property. My goal is to achieve something like the following:
@foreach (var item in Model)
{
var result = MyClass.GetOrder(item);
<h2>@item.Date.Substring(0,4)</h2>
<p style="color:@result[0].Value3">@result[0].Key , @result[0].Value</p>
<p style="color:@result[1].Value3">@result[1].Key , @result[1].Value</p>
<p style="color:@result[2].Value3">@result[2].Key , @result[2].Value</p>
<p style="color:@result[3].Value3">@result[3].Key , @result[3].Value</p>
}
Method Details
public static List<KeyValuePair<string, int>> GetOrder(MyClass myclass)
{
var NameVal = new List<KeyValuePair<string, int>>()
{
new KeyValuePair<string, int>(myclass.Name1, Convert.ToInt32(myclass.Val1)),
new KeyValuePair<string, int>(myclass.Name2, Convert.ToInt32(myclass.Val2)),
new KeyValuePair<string, int>(myclass.Name3, Convert.ToInt32(myclass.Val3)),
new KeyValuePair<string, int>(myclass.Name4, Convert.ToInt32(myclass.Val4))
};
var result = NameVal.OrderByDescending(key => key.Value);
return result.ToList();
}