public static string ObtenerClase(TipoLabel tipo) { string clase = ""; switch (tipo) { // case TipoLabel.Normal: clase = "disabled"; break; case TipoLabel.Marcado: clase = "marcado"; break; case TipoLabel.LadoSuperior: clase = "obligatorio"; break; } return(clase); }
public static MvcHtmlString MTCLabel(this HtmlHelper html, string texto, string id, string @for, TipoLabel tipo = TipoLabel.Normal, object htmlAttributesInput = null) { var nombre = (string)id; string textoValor = ""; textoValor = texto; var label = new TagBuilder("label"); label.Attributes.Add("for", @for); //label.Attributes.Add("value", textoValor); label.InnerHtml = textoValor; if (htmlAttributesInput != null) { LlenarValores(label, htmlAttributesInput); } return(new MvcHtmlString(label.ToString())); }
/* * public static MvcHtmlString MTCEditorFor<TModel, TTextProperty>(this HtmlHelper<TModel> html, * Expression<Func<TModel, TTextProperty>> texto, TipoInput tipo = TipoInput.Normal, object htmlAttributesContenedor = null, * object htmlAttributesInput = null * ) * { * * var nombre = (string)ModelMetadata.FromLambdaExpression(texto, html.ViewData).PropertyName; * * string textoValor = ""; * if (ModelMetadata.FromLambdaExpression(texto, html.ViewData).Model != null) * { * textoValor = ModelMetadata.FromLambdaExpression(texto, html.ViewData).Model.ToString(); * } * * var wrapper = new TagBuilder("div"); * wrapper.AddCssClass("form_campo " + ObtenerClase(tipo)); * * * if (htmlAttributesContenedor != null) * { * LlenarValores(wrapper, htmlAttributesContenedor); * } * * * var inputText = new TagBuilder("input"); * inputText.AddCssClass("text-box single-line"); * inputText.Attributes.Add("name", nombre); * inputText.Attributes.Add("id", nombre); * inputText.Attributes.Add("value", textoValor); * * * if (string.IsNullOrEmpty(ModelMetadata.FromLambdaExpression(texto, html.ViewData).DataTypeName)) * { * inputText.Attributes.Add("type", "text"); * } * else * { * inputText.Attributes.Add("type", ModelMetadata.FromLambdaExpression(texto, html.ViewData).DataTypeName); * } * * if (tipo == TipoInput.Deshabilitado) * { * inputText.Attributes.Add("readonly", "readonly"); * } * * if (htmlAttributesInput != null) * { * LlenarValores(inputText, htmlAttributesInput); * } * * string prefix = ExpressionHelper.GetExpressionText(texto); * if (string.IsNullOrEmpty(prefix)) * prefix = "empty"; * * var validationAttributes = html.GetUnobtrusiveValidationAttributes(prefix); * foreach (KeyValuePair<string, object> pair in validationAttributes) * { * inputText.MergeAttribute(pair.Key, pair.Value.ToString()); * } * * MvcHtmlString validation = html.ValidationMessageFor(texto); * if (validation != null) * { * inputText.InnerHtml = validation.ToString(); * } * * wrapper.InnerHtml = inputText.ToString(); * * return new MvcHtmlString(wrapper.ToString()); * * } */ public static MvcHtmlString MTCLabelFor <TModel, TTextProperty>(this HtmlHelper <TModel> html, Expression <Func <TModel, TTextProperty> > texto, TipoLabel tipo = TipoLabel.Normal, object htmlAttributesContenedor = null, object htmlAttributesInput = null ) { var nombre = (string)ModelMetadata.FromLambdaExpression(texto, html.ViewData).DisplayName; string textoValor = ""; if (ModelMetadata.FromLambdaExpression(texto, html.ViewData).Model != null) { textoValor = ModelMetadata.FromLambdaExpression(texto, html.ViewData).Model.ToString(); } //var wrapper = new TagBuilder("div"); //wrapper.AddCssClass("form_label " + ObtenerClase(tipo)); //if (htmlAttributesContenedor != null) //{ // LlenarValores(wrapper, htmlAttributesContenedor); //} var inputText = new TagBuilder("label"); inputText.Attributes.Add("for", nombre); inputText.Attributes.Add("value", nombre); inputText.InnerHtml = nombre; if (htmlAttributesInput != null) { LlenarValores(inputText, htmlAttributesInput); } //wrapper.InnerHtml = inputText.ToString(); return(new MvcHtmlString(inputText.ToString())); }