60 lines
2.4 KiB
C#
60 lines
2.4 KiB
C#
using System;
|
|
using System.Linq.Expressions;
|
|
using System.Web.Mvc;
|
|
using Kendo.Mvc.UI;
|
|
using Kendo.Mvc.UI.Fluent;
|
|
using Kreta.Resources;
|
|
|
|
namespace Kreta.Web.Helpers.Unhacked
|
|
{
|
|
public static class ComboBoxExtensions
|
|
{
|
|
public struct ComboBoxParameters
|
|
{
|
|
public string Name;
|
|
public string Action;
|
|
public string Controller;
|
|
public string Area;
|
|
public string Placeholder;
|
|
public string Language;
|
|
public FilterType FilterType;
|
|
public string ContentType;
|
|
public bool ServerFiltering;
|
|
|
|
public ComboBoxParameters(string name, string action, string controller = "Enum", string area = "", string placeholder = null, string language = "Magyar",
|
|
FilterType filterType = FilterType.Contains, string contentType = Kreta.Core.Constants.ContentTypes.ApplicationJson, bool serverFiltering = false)
|
|
{
|
|
Name = name;
|
|
Action = action;
|
|
Controller = controller;
|
|
Area = area;
|
|
Language = language;
|
|
FilterType = filterType;
|
|
ContentType = contentType;
|
|
ServerFiltering = serverFiltering;
|
|
Placeholder = placeholder ?? CommonResource.PleaseChoose;
|
|
}
|
|
}
|
|
public static ComboBoxBuilder KendoComboBoxFor<TModel, TProperty>(this HtmlHelper<TModel> html, Expression<Func<TModel, TProperty>> expression, ComboBoxParameters parameters)
|
|
{
|
|
return html.Kendo().ComboBoxFor(expression)
|
|
.Name(parameters.Name + "ComboBox")
|
|
.Placeholder(parameters.Placeholder)
|
|
.DataTextField(parameters.Language)
|
|
.DataValueField("Id")
|
|
.Filter(parameters.FilterType)
|
|
.DataSource(source =>
|
|
{
|
|
source.Custom()
|
|
.ServerFiltering(parameters.ServerFiltering)
|
|
.Transport(transport =>
|
|
{
|
|
transport.Read(read =>
|
|
{
|
|
read.ContentType(parameters.ContentType).Action(parameters.Action, parameters.Controller, new { parameters.Area });
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}
|