1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- 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<string, object> htmlAttributes = null)
- {
- return MvcHtmlString.Create(Bowin.Web.Controls.Mvc.Combotree.CreateControl(combotreeOptions, htmlAttributes).Render());
- }
- public static MvcHtmlString CombotreeFor<TModel, TProperty>(
- this HtmlHelper<TModel> htmlHelper
- , Expression<Func<TModel, TProperty>> expression
- , string dataSourceUrl)
- {
- var combotreeOptions = new CombotreeOptions { DataSourceUrl = dataSourceUrl };
- var htmldic = AnalyzingExpression<TModel, TProperty>(htmlHelper, expression, combotreeOptions);
- return Combotree(htmlHelper, combotreeOptions, htmldic);
- }
- public static MvcHtmlString CombotreeFor<TModel, TProperty>(
- this HtmlHelper<TModel> htmlHelper
- , Expression<Func<TModel, TProperty>> expression
- , CombotreeOptions combotreeOptions)
- {
- var htmldic = AnalyzingExpression<TModel, TProperty>(htmlHelper, expression, combotreeOptions);
- return Combotree(htmlHelper, combotreeOptions, htmldic);
- }
- public static MvcHtmlString CombotreeFor<TModel, TProperty>(
- this HtmlHelper<TModel> htmlHelper
- , Expression<Func<TModel, TProperty>> expression
- , CombotreeOptions combotreeOptions
- , IDictionary<string, object> htmlAttributes)
- {
- AnalyzingExpression<TModel, TProperty>(htmlHelper, expression, combotreeOptions);
- return Combotree(htmlHelper, combotreeOptions, htmlAttributes);
- }
- private static IDictionary<string,object> AnalyzingExpression<TModel, TProperty>(HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, CombotreeOptions combotreeOptions)
- {
- if (expression == null)
- {
- throw new ArgumentNullException("expression");
- }
- ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression<TModel, TProperty>(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);
- }
- }
- }
|