kreta/KretaWeb/Helpers/Unhacked/RadioButtonExtensions.cs
2024-03-13 00:33:46 +01:00

27 lines
980 B
C#

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Mvc;
using Kendo.Mvc.UI;
using Kendo.Mvc.UI.Fluent;
namespace Kreta.Web.Helpers.Unhacked
{
public static class RadioButtonExtensions
{
public static List<RadioButtonBuilder> KendoRadioButtonsFor<TModel, TProperty, T>(this HtmlHelper<TModel> html,
Expression<Func<TModel, TProperty>> expression, List<T> options, Expression<Func<T, object>> idExpression, Expression<Func<T, string>> labelExpression)
{
var idMethod = idExpression.Compile();
var labelMethod = labelExpression.Compile();
var radioButtonBuilders = new List<RadioButtonBuilder>();
foreach (var option in options)
{
radioButtonBuilders.Add(html.Kendo().RadioButtonFor(expression).Label(labelMethod(option)).Value(idMethod(option)));
}
return radioButtonBuilders;
}
}
}