public static MvcHtmlString RPDateTimeFor <TModel, TProperty>( this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, DataTypeUI dataType = DataTypeUI.Undefined, DateTimeFormatUI dateTimeFormat = DateTimeFormatUI.Date, string labelMessage = null, string placeholderMessage = null) { var metadata = htmlHelper.GetModelMetadata(expression, labelMessage, placeholderMessage); var viewModel = new DateTimeViewModel(metadata, dataType, dateTimeFormat); var htmlAttributes = new Dictionary <string, object>(); if (!string.IsNullOrEmpty(viewModel.PlaceholderMessage)) { htmlAttributes.Add("placeholder", viewModel.PlaceholderMessage); } htmlAttributes.Add("type", viewModel.DataType.GetMetadata().Value); switch (dateTimeFormat) { case DateTimeFormatUI.Date: htmlAttributes.Add("class", "form-control datepicker"); break; case DateTimeFormatUI.DateTime: htmlAttributes.Add("class", "form-control datetimepicker"); break; } viewModel.Input = htmlHelper.TextBoxFor(expression, ((DateTime?)viewModel.Model).ToShortDateString(CultureManager.DateTimeFormat), htmlAttributes); return(htmlHelper.Partial(Mvc.View.UI.DateTime, viewModel)); }
public TextBoxViewModel(ModelMetadata metadata, DataTypeUI dataType) : base(metadata) { if (string.IsNullOrEmpty(PlaceholderMessage)) { PlaceholderMessage = StyleContext.GetTranslation(Dom.Translation.Common.Enter); } DataType = dataType; }
public DateTimeViewModel(ModelMetadata metadata, DataTypeUI dataType, DateTimeFormatUI dateTimeFormat) : base(metadata) { if (string.IsNullOrEmpty(PlaceholderMessage)) { switch (dateTimeFormat) { case DateTimeFormatUI.Date: PlaceholderMessage = StyleContext.GetTranslation(Dom.Translation.Common.DateFormat); break; case DateTimeFormatUI.DateTime: PlaceholderMessage = StyleContext.GetTranslation(Dom.Translation.Common.DateTimeFormat); break; } } DataType = dataType; DateTimeFormat = dateTimeFormat; }
public static MvcHtmlString RPTextBoxFor <TModel, TProperty>( this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression, DataTypeUI dataType = DataTypeUI.Undefined, string labelMessage = null, string placeholderMessage = null, string cssClass = null) { var metadata = htmlHelper.GetModelMetadata(expression, labelMessage, placeholderMessage); var viewModel = new TextBoxViewModel(metadata, dataType); var htmlAttributes = new Dictionary <string, object>(); if (!string.IsNullOrEmpty(viewModel.PlaceholderMessage)) { htmlAttributes.Add("placeholder", viewModel.PlaceholderMessage); } htmlAttributes.Add("type", viewModel.DataType.GetMetadata().Value); htmlAttributes.Add("class", $"form-control input-val {cssClass}"); viewModel.Input = htmlHelper.TextBoxFor(expression, htmlAttributes); return(htmlHelper.Partial(Mvc.View.UI.TextBox, viewModel)); }