public static MvcHtmlString BSFGForMetaData <TModel>( this HtmlHelper <TModel> html, MetaProduct meta, int num, int col_sm) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<div class=\"form-group\">"); var name = (typeof(TypeOfMetaProduct).GetMember(meta.Type.ToString()).First().GetCustomAttributes(typeof(DisplayAttribute), true).First() as DisplayAttribute).Name; sb.AppendLine(LabelExtensions .Label(html, name, new { @class = String.Format("col-sm-{0} control-label", 12 - col_sm) }).ToHtmlString()); sb.AppendLine(String.Format("<div class=\"col-sm-{0}\">", col_sm)); sb.AppendLine("<div class=\"input-group\">"); sb.AppendLine(InputExtensions .Hidden(html, String .Format("MetaData[{0}].Type", num), meta.Type.ToString()).ToHtmlString()); switch (meta.Type) { case TypeOfMetaProduct.Author: case TypeOfMetaProduct.Country: case TypeOfMetaProduct.Director: case TypeOfMetaProduct.FromURI: case TypeOfMetaProduct.Genre: case TypeOfMetaProduct.InRole: case TypeOfMetaProduct.Name: case TypeOfMetaProduct.PosterFromURI: case TypeOfMetaProduct.Type: case TypeOfMetaProduct.View: case TypeOfMetaProduct.NumberOfEpisode: sb.AppendLine(InputExtensions .TextBox(html, String .Format("MetaData[{0}].String", num), meta.String, new { @class = "form-control" }).ToHtmlString()); break; case TypeOfMetaProduct.Begin: case TypeOfMetaProduct.End: sb.AppendLine(InputExtensions .TextBox(html, String .Format("MetaData[{0}].DateTime", num), meta.Date.ToShortDateString(), new { @class = "form-control" }).ToHtmlString()); break; case TypeOfMetaProduct.Ended: sb.AppendLine(InputExtensions .CheckBox(html, String .Format("MetaData[{0}].Bool", num), meta.Bool, new { @class = "form-control" }).ToHtmlString()); break; } sb.AppendLine("<span class=\"input-group-btn\">"); sb.AppendLine(String.Format( "<input name =\"MetaData[{0}].String\" type=\"submit\" value=\"Удалить\" class=\"btn btn-success\">", num)); sb.AppendLine("</span>"); sb.AppendLine("</div>"); sb.AppendLine("</div>"); sb.AppendLine("</div>"); return(new MvcHtmlString(sb.ToString())); }
public static MvcHtmlString JQM_SelectMenu(this HtmlHelper htmlHelper, string name, string label, MultiSelectList values, string optionLabel = null, SelectMenuConfig config = null) { TagBuilder tagResult = new TagBuilder("div"); tagResult.MergeAttribute("class", "ui-field-contain"); if (config == null) { config = new SelectMenuConfig(); } tagResult.InnerHtml += LabelExtensions.Label(htmlHelper, "", label).ToHtmlString(); tagResult.InnerHtml += SelectExtensions.DropDownList(htmlHelper, name, values, optionLabel, (config != null) ? config.GetAttributes() : null).ToHtmlString(); return(tagResult.ToHtml()); }
public static MvcHtmlString BSFGForEnumDDL <TModel>( this HtmlHelper <TModel> html, Type MyEnum, string ValName, string label, int col_sm, string btn_value, string btn_name, string defaultvalue) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<div class=\"form-group\">"); sb.AppendLine(LabelExtensions .Label(html, ValName, label, new { @class = String.Format("col-sm-{0} control-label", 12 - col_sm) }).ToHtmlString()); sb.AppendLine(String.Format("<div class=\"col-sm-{0}\">", col_sm)); sb.AppendLine("<div class=\"input-group\">"); sb.Append(String.Format("<select name=\"{0}\" class=\"form-control\">", ValName)); foreach (var iten in Enum.GetValues(MyEnum)) { var value = iten.ToString(); var name = (MyEnum.GetMember(iten.ToString()).First().GetCustomAttributes(typeof(DisplayAttribute), true).First() as DisplayAttribute).Name; //var da = iten.GetCustomAttributes(typeof(DisplayAttribute),true); if (value == defaultvalue) { sb.Append(String.Format("<option selected value=\"{0}\">", value)); } else { sb.Append(String.Format("<option value=\"{0}\">", value)); } sb.Append(name); sb.Append("</option>"); } sb.Append("</select>"); sb.AppendLine("<span class=\"input-group-btn\">"); sb.AppendLine(String.Format( "<input name =\"{0}\" type=\"submit\" value=\"{1}\" class=\"btn btn-success\">", btn_name, btn_value)); sb.AppendLine("</span>"); sb.AppendLine("</div>"); sb.AppendLine("</div>"); sb.AppendLine("</div>"); return(new MvcHtmlString(sb.ToString())); }
public static MvcHtmlString BSFGLabel <TModel, TProperty>( this HtmlHelper <TModel> html, Expression <Func <TModel, TProperty> > expression, int col_sm) { StringBuilder sb = new StringBuilder(); sb.AppendLine("<div class=\"form-group\">"); sb.AppendLine(LabelExtensions .LabelFor(html, expression, new { @class = String.Format("col-sm-{0} control-label", 12 - col_sm) }).ToHtmlString()); sb.AppendLine(String.Format("<div class=\"col-sm-{0}\">", col_sm)); string value; try { value = expression.Compile()(html.ViewData.Model).ToString(); } catch { value = ""; } sb.AppendLine(LabelExtensions .Label(html, value, new { @class = "form-control" }).ToHtmlString()); sb.AppendLine("</div>"); sb.AppendLine("</div>"); return(new MvcHtmlString(sb.ToString())); }
// LabelExtensions public static MvcHtmlString Label(this HtmlHelper htmlHelper, string expression) { return(LabelExtensions.Label(htmlHelper, expression)); }
public static MvcHtmlString ChangeableFor <TModel, TValue, TType>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, Changeable <TType> changeable) { // helper to take our Changeable<T> property, and create lambdas to get var controller = html.ViewContext.Controller; var actionName = controller.ValueProvider.GetValue("action").RawValue.ToString(); var allMethods = controller.GetType().GetMethods(); var methods = allMethods.Where(m => m.Name == actionName); foreach (var method in methods) { var attributes = method.GetCustomAttributes(true); foreach (var attribute in attributes) { if (attribute.GetType().Equals(typeof(HttpPostAttribute))) { var a = attribute; } } } var name = ExpressionHelper.GetExpressionText(expression); if (String.IsNullOrEmpty(name)) { throw new ArgumentNullException("name", "Name cannot be null"); } // get the metadata for our Changeable<T> property var metadata = ModelMetadata.FromLambdaExpression(expression, html.ViewData); var type = metadata.ModelType; var containerType = metadata.ContainerType; // create a lambda expression to get the value of our Changeable<T> var arg = Expression.Parameter(containerType, "x"); Expression expr = arg; expr = Expression.Property(expr, name); expr = Expression.Property(expr, "Value"); var funcExpr = Expression.Lambda(expr, arg) as Expression <Func <TModel, TType> >; var valueModelMetadata = ModelMetadata.FromLambdaExpression(funcExpr, html.ViewData); // create a lambda expression to get whether our Changeable<T> has changed Expression exprChanged = arg; exprChanged = Expression.Property(exprChanged, name); exprChanged = Expression.Property(exprChanged, "Changed"); var funcExprChanged = Expression.Lambda(exprChanged, arg) as Expression <Func <TModel, bool> >; // use a stringbuilder for our HTML markup // return label, checkbox, hidden input, EDITOR, and validation message field // NOTE: this is over-simplified markup! // ALSO NOTE: the EditorFor is passed the strongly typed model taken from our T. Bonus! var htmlSb = new StringBuilder("\n"); htmlSb.Append(LabelExtensions.Label(html, metadata.GetDisplayName())); htmlSb.Append("<br />\n"); htmlSb.Append(InputExtensions.CheckBoxFor(html, funcExprChanged)); htmlSb.Append(" Changed<br />\n"); htmlSb.Append(InputExtensions.Hidden(html, name + ".OldValue", valueModelMetadata.Model) + "\n"); htmlSb.Append(EditorExtensions.EditorFor(html, funcExpr, new KeyValuePair <string, object>("parentMetadata", metadata))); //new object[] { "parentMetadata", metadata })); htmlSb.Append(ValidationExtensions.ValidationMessageFor(html, funcExpr)); htmlSb.Append("<br />\n"); return(new MvcHtmlString(htmlSb.ToString())); }
public static MvcHtmlString LocalizedLabel(this HtmlHelper helper, string keyPath, object attributes) { string required = ResourceManager.GetValidators(keyPath).Contains("required") ? "*" : ""; return(LabelExtensions.Label(helper, "", ResourceManager.GetString(keyPath) + required, attributes)); }