protected virtual HtmlString GeneratePassword(ModelMetadata metadata, string name, object value, object htmlAttributes) { var tagBuilder = _htmlGenerator.GeneratePassword( ViewContext, metadata, name, value, htmlAttributes); if (tagBuilder == null) { return(HtmlString.Empty); } return(tagBuilder.ToHtmlString(TagRenderMode.SelfClosing)); }
protected virtual IHtmlContent GeneratePassword( ModelExplorer modelExplorer, string expression, object value, object htmlAttributes) { var tagBuilder = _htmlGenerator.GeneratePassword( ViewContext, modelExplorer, expression, value, htmlAttributes); if (tagBuilder == null) { return(HtmlString.Empty); } return(tagBuilder); }
protected virtual HtmlString GeneratePassword( ModelExplorer modelExplorer, string expression, object value, object htmlAttributes) { var tagBuilder = _htmlGenerator.GeneratePassword( ViewContext, modelExplorer, expression, value, htmlAttributes); if (tagBuilder == null) { return(HtmlString.Empty); } return(tagBuilder.ToHtmlString(TagRenderMode.SelfClosing)); }
private void WritePassword(TextWriter writer) { bool IsNoAutoComplete = AttributeHelper.IsAttributeDefined <NoAutoCompleteAttribute>( For.ModelExplorer.Metadata.ContainerType, For.ModelExplorer.Metadata.PropertyName); var tagBuilder = _htmlGenerator.GeneratePassword( ViewContext, For.ModelExplorer, For.Name, value: For.Model, htmlAttributes: new { @class = IsNoAutoComplete ? "form-control no-auto-complete" : "form-control" }); if (IsNoAutoComplete) { tagBuilder.Attributes.Add("autocomplete", "new-password"); } WritePrefix(writer, PrefixAttribute.Position.Value); tagBuilder.WriteTo(writer, _htmlEncoder); }
void BuildInputType(PropertyInfo prop, FormGroupModel group, ModelExplorer modelExplorer) { //判断是否有设置dataType var dataType = prop.GetCustomAttribute <DataTypeAttribute>(); if (dataType?.DataType != null) { switch (dataType.DataType) { case DataType.Text: group.Input = Generator.GenerateTextBox(viewContext, modelExplorer, prop.Name, null, null, new { @class = "form-control" }); group.TextDanger = Generator.GenerateValidationMessage(viewContext, modelExplorer, prop.Name, null, viewContext.ValidationMessageElement, new { @class = "text-danger" }); break; case DataType.Password: group.Input = Generator.GeneratePassword(viewContext, modelExplorer, prop.Name, null, new { @class = "form-control" }); group.TextDanger = Generator.GenerateValidationMessage(viewContext, modelExplorer, prop.Name, null, viewContext.ValidationMessageElement, new { @class = "text-danger" }); break; case DataType.PhoneNumber: group.Input = Generator.GenerateTextBox(viewContext, modelExplorer, prop.Name, null, null, new { @class = "form-control", @type = "tel" }); group.TextDanger = Generator.GenerateValidationMessage(viewContext, modelExplorer, prop.Name, null, viewContext.ValidationMessageElement, new { @class = "text-danger" }); break; case DataType.MultilineText: group.Input = Generator.GenerateTextArea(viewContext, modelExplorer, prop.Name, 2, 1, new { @class = "form-control" }); group.TextDanger = Generator.GenerateValidationMessage(viewContext, modelExplorer, prop.Name, null, viewContext.ValidationMessageElement, new { @class = "text-danger" }); break; case DataType.EmailAddress: group.Input = Generator.GenerateTextBox(viewContext, modelExplorer, prop.Name, null, null, new { @class = "form-control", @type = "email" }); group.TextDanger = Generator.GenerateValidationMessage(viewContext, modelExplorer, prop.Name, null, viewContext.ValidationMessageElement, new { @class = "text-danger" }); break; case DataType.Url: group.Input = Generator.GenerateTextBox(viewContext, modelExplorer, prop.Name, null, null, new { @class = "form-control", @type = "url" }); group.TextDanger = Generator.GenerateValidationMessage(viewContext, modelExplorer, prop.Name, null, viewContext.ValidationMessageElement, new { @class = "text-danger" }); break; default: break; } return; } // 自定义selectControl控件 var selectControl = prop.GetCustomAttribute <SelectControlAttribute>(); if (selectControl != null) { if (selectControl.Type == ItemDataType.StaticItems) { List <SelectListItem> nodes = new List <SelectListItem>(); var items = modelType.GetProperty(selectControl.ItemsName); if (items != null) { nodes = items.GetValue(viewModel.Model, null) as List <SelectListItem>; } group.Input = Generator.GenerateSelect(viewContext, modelExplorer, null, prop.Name, nodes?.ToList(), false, new { @class = "form-control" }); var initValue = nodes.FirstOrDefault(d => d.Selected)?.Value; var ngInit = initValue?.Length > 0 ? initValue : nodes[0].Value; group.Input.Attributes.Add("ng-init", $"Model.Active.{prop.Name}='{ngInit}'"); } else { string url = selectControl.Type == ItemDataType.AbsUrl ? selectControl.Url : $"http://{viewContext.HttpContext.Request.Host.Value}/{selectControl.Controller}/{selectControl.Action}"; group.Input = new TagBuilder("select-control"); group.Input.AddCssClass("form-control"); group.Input.Attributes.Add("id", prop.Name); group.Input.Attributes.Add("name", prop.Name); group.Input.Attributes.Add("request-url", url); group.Input.Attributes.Add("request-init", $"Model.Active.{prop.Name}"); } return; } //自定义 radiolist 控件 //var radioListControl = prop.GetCustomAttribute<RadioListAttribute>(); //if (radioListControl != null) //{ // var values = radioListControl.Values.Split(','); // var tests = radioListControl.Texts.Split(','); // if (values.Length == tests.Length) // { // group.Input = new TagBuilder("div"); // var index = 0; // foreach (var item in values) // { // group.Input = new TagBuilder("label"); // group.Input.InnerHtml.AppendHtml($"<input type='radio' name='{prop.Name}' ng-model='Model.Active.{item}' class='form-control'/>{tests[index++]}"); // } // } // return; //} if (prop.GetType() == typeof(int) || prop.GetType() == typeof(float) || prop.GetType() == typeof(double)) { group.Input = Generator.GenerateTextBox(viewContext, modelExplorer, prop.Name, null, null, new { @class = "form-control", @type = "number" }); } else { group.Input = Generator.GenerateTextBox(viewContext, modelExplorer, prop.Name, null, null, new { @class = "form-control" }); } group.TextDanger = Generator.GenerateValidationMessage(viewContext, modelExplorer, prop.Name, null, viewContext.ValidationMessageElement, new { @class = "text-danger" }); }
public TagBuilder GeneratePassword(ViewContext viewContext, ModelExplorer modelExplorer, string expression, object value, object htmlAttributes) { return(_htmlGenerator.GeneratePassword(viewContext, modelExplorer, expression, value, htmlAttributes)); }