You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
614 B
19 lines
614 B
using Microsoft.AspNetCore.Mvc.Rendering;
|
|
using System.Linq;
|
|
|
|
namespace TeacherExt.Controllers
|
|
{
|
|
public static class Ext
|
|
{
|
|
public static SelectList ToSelectList(this string[] array, string selected)
|
|
{
|
|
return new SelectList(array.Select(o => new SelectListItem { Value = o, Text = o }), "Value", "Text", selected);
|
|
}
|
|
|
|
public static string GetText(this SelectList list, object value)
|
|
{
|
|
var items = list.Items.Cast<SelectListItem>().ToList();
|
|
return items.FirstOrDefault(o => o.Value == value?.ToString())?.Text;
|
|
}
|
|
}
|
|
} |