internal static IHtmlContent GenerateHtml <TModel>( IHtmlHelper <TModel> htmlHelper, Expression <Func <TModel, string> > propertyLambdaExpression, int?rows = null, LabelViewModel labelOptions = null, HintViewModel hintOptions = null, FormGroupViewModel formGroupOptions = null ) where TModel : GovUkViewModel { PropertyInfo property = ExpressionHelpers.GetPropertyFromExpression(propertyLambdaExpression); ThrowIfPropertyDoesNotHaveCharacterCountAttribute(property); string propertyName = property.Name; TModel model = htmlHelper.ViewData.Model; string currentValue = ExtensionHelpers.GetCurrentValue(model, property, propertyLambdaExpression); string id = $"GovUk_{propertyName}"; if (labelOptions != null) { labelOptions.For = id; } int maximumCharacters = GetMaximumCharacters(property); var characterCountViewModel = new CharacterCountViewModel { Name = $"GovUk_Text_{propertyName}", Id = id, MaxLength = maximumCharacters, Value = currentValue, Rows = rows, Label = labelOptions, Hint = hintOptions, FormGroup = formGroupOptions }; if (model.HasErrorFor(property)) { characterCountViewModel.ErrorMessage = new ErrorMessageViewModel { Text = model.GetErrorFor(property) }; } return(htmlHelper.Partial("/GovUkDesignSystemComponents/CharacterCount.cshtml", characterCountViewModel)); }
public static IHtmlContent GovUkCharacterCount( this IHtmlHelper htmlHelper, CharacterCountViewModel characterCountViewModel) { return(htmlHelper.Partial("/GovUkDesignSystemComponents/CharacterCount.cshtml", characterCountViewModel)); }
public static IHtmlContent GovUkCharacterCount( this IHtmlHelper htmlHelper, CharacterCountViewModel characterCountViewModel) { return(htmlHelper.Partial("~/Partials/CharacterCount.cshtml", characterCountViewModel)); }