using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Mvc; using System.Linq.Expressions; using System.Web.Mvc.Html; using Bowin.Web.Controls.Mvc; using Bowin.Web.Controls.Mvc.Utility; namespace System.Web.Mvc { public static class CombotreeExtensions { public static System.Web.Mvc.MvcHtmlString Combotree( this System.Web.Mvc.HtmlHelper htmlHelper , CombotreeOptions combotreeOptions , IDictionary htmlAttributes = null) { return MvcHtmlString.Create(Bowin.Web.Controls.Mvc.Combotree.CreateControl(combotreeOptions, htmlAttributes).Render()); } public static MvcHtmlString CombotreeFor( this HtmlHelper htmlHelper , Expression> expression , string dataSourceUrl) { var combotreeOptions = new CombotreeOptions { DataSourceUrl = dataSourceUrl }; var htmldic = AnalyzingExpression(htmlHelper, expression, combotreeOptions); return Combotree(htmlHelper, combotreeOptions, htmldic); } public static MvcHtmlString CombotreeFor( this HtmlHelper htmlHelper , Expression> expression , CombotreeOptions combotreeOptions) { var htmldic = AnalyzingExpression(htmlHelper, expression, combotreeOptions); return Combotree(htmlHelper, combotreeOptions, htmldic); } public static MvcHtmlString CombotreeFor( this HtmlHelper htmlHelper , Expression> expression , CombotreeOptions combotreeOptions , IDictionary htmlAttributes) { AnalyzingExpression(htmlHelper, expression, combotreeOptions); return Combotree(htmlHelper, combotreeOptions, htmlAttributes); } private static IDictionary AnalyzingExpression(HtmlHelper htmlHelper, Expression> expression, CombotreeOptions combotreeOptions) { if (expression == null) { throw new ArgumentNullException("expression"); } ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData); string fullHtmlFieldName = htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(ExpressionHelper.GetExpressionText(expression)); combotreeOptions.Name = fullHtmlFieldName; if (modelMetadata.Model != null) { //Guid emptyg = Guid.Parse(modelMetadata.Model.ToString()); //if (emptyg != Guid.Empty) //{ combotreeOptions.SelectedValue = modelMetadata.Model; //} } return htmlHelper.GetUnobtrusiveValidationAttributes(fullHtmlFieldName, modelMetadata); } } }