public static MvcHtmlString JsTreeFor <TModel>(this HtmlHelper <TModel> html, Expression <Func <TModel, JsTree> > expression) { String name = ExpressionHelper.GetExpressionText(expression) + ".SelectedIds"; JsTree model = ModelMetadata.FromLambdaExpression(expression, html.ViewData).Model as JsTree; return(new MvcHtmlString(HiddenIdsFor(name, model) + JsTreeFor(name, model))); }
private static String JsTreeFor(String name, JsTree model) { TagBuilder tree = new TagBuilder("div"); tree.AddCssClass("js-tree-view"); tree.Attributes["for"] = name; Add(tree, model.Nodes); return(tree.ToString()); }
private static String HiddenIdsFor(String name, JsTree model) { StringBuilder inputs = new StringBuilder(); TagBuilder input = new TagBuilder("input"); input.Attributes["type"] = "hidden"; input.Attributes["name"] = name; foreach (Int32 id in model.SelectedIds) { input.Attributes["value"] = id.ToString(); inputs.Append(input.ToString(TagRenderMode.SelfClosing)); } TagBuilder ids = new TagBuilder("div"); ids.AddCssClass("js-tree-view-ids"); ids.InnerHtml = inputs.ToString(); return(ids.ToString()); }