public static MvcHtmlString LookUpCr <TModel>(this HtmlHelper helper, string id, string name, string title, TreeInfo treeInfo, string propertyNameForBinding, bool isMultiSelect, object htmlAttributes, bool readOnly, Dictionary <string, object> lookupHtmlAttributes, params ValidationBase[] validationCr) where TModel : IViewModel, new() { Id = id; TagBuilder container = new TagBuilder("span"); container.AddCssClass("rp-lookup"); if (htmlAttributes != null) { var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); container.MergeAttributes(attributes); } TagBuilder containerState = new TagBuilder("span"); //-----MultiSelect Kendo.Mvc.UI.Fluent.MultiSelectBuilder multiSelect = helper.MultiSelectCr(propertyNameForBinding, treeInfo.DataTextField, treeInfo.DataSource.ModelCr.ModelIdName, Kendo.Mvc.UI.FilterType.Contains); lookupHtmlAttributes = lookupHtmlAttributes ?? new Dictionary <string, object>(); Dictionary <string, string> _htmlAttributes = null; if (validationCr != null && validationCr.Count() > 0) { _htmlAttributes = CreateValidationForlookup(lookupHtmlAttributes, validationCr); } else { _htmlAttributes = lookupHtmlAttributes.ToDictionary(t => t.Key, t => (string)t.Value); } if (readOnly) { _htmlAttributes.Add("readOnly", "true"); } if (!string.IsNullOrEmpty(Id)) { _htmlAttributes.Add("id", Id); } if (!string.IsNullOrEmpty(name)) { _htmlAttributes.Add("name", name); } multiSelect.HtmlAttributes(_htmlAttributes.ToDictionary(t => t.Key, t => (object)t.Value)); var multiSelectHtml = multiSelect.ToHtmlString(); containerState.AddCssClass(multiSelectHtml.Contains("data-val-required") ? StyleKind.RequiredInput : StyleKind.OptionalInput); //string treeID = string.Format("lookupTree_{0}", Id); //treeInfo.Name = treeID; //var treeInfoHashKey = treeInfo.GetHashCode(); //AllTreeLookups.TryAdd(treeInfoHashKey, treeInfo); string treeID = string.Format("lookupTree_{0}", Id); ///we must new from static instance to set info itself var info = treeInfo.DeepCopy <TreeInfo>(); info.Name = treeID; var treeInfoKey = string.Format("{0}_{1}", treeInfo.GetHashCode(), treeID); AllTreeLookups.TryAdd(treeInfoKey, info); var lookupInfo = new Lookup.Tree { Title = title, LookupName = Id, TreeID = treeID, // ViewModel = typeof(TModel).FullName, ViewModel = typeof(TModel).AssemblyQualifiedName, ViewInfoKey = treeInfoKey, UseMultiSelect = true, PropertyNameForDisplay = treeInfo.DataTextField, PropertyNameForValue = treeInfo.DataSource.ModelCr.ModelIdName, PropertyNameForBinding = propertyNameForBinding }; //-----Create lookup---- containerState.InnerHtml = multiSelectHtml + CreatLookupButton(lookupInfo); container.InnerHtml = containerState.ToString(); container.InnerHtml = containerState.ToString(); return(MvcHtmlString.Create(container.ToString())); }
public static MvcHtmlString LookUpCr <TModel>(this HtmlHelper helper, string id, string name, string title, TreeInfo treeInfo, string propertyNameForBinding , object htmlAttributes, bool readOnly, Dictionary <string, object> lookupHtmlAttributes, params ValidationBase[] validationCr) where TModel : IViewModel, new() { Id = id; TagBuilder container = new TagBuilder("span"); if (htmlAttributes != null) { var attributes = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); container.MergeAttributes(attributes); } TagBuilder containerState = new TagBuilder("span"); //-----textbox MvcHtmlString textbox; lookupHtmlAttributes = lookupHtmlAttributes ?? new Dictionary <string, object>(); //---value TagBuilder hiddenValue = new TagBuilder("input"); hiddenValue.MergeAttribute("type", "hidden"); hiddenValue.MergeAttribute("id", propertyNameForBinding); if (!string.IsNullOrEmpty(name)) { hiddenValue.MergeAttribute("name", name); } hiddenValue.MergeAttribute("data-bind", string.Format("value:{0}", propertyNameForBinding)); if (validationCr != null && validationCr.Count() > 0) { hiddenValue.MergeAttributes(CreateValidationForlookup(lookupHtmlAttributes, validationCr)); } textbox = helper.TextBoxCr(Id, readOnly, lookupHtmlAttributes); //string treeID = string.Format("lookupTree_{0}", Id); //treeInfo.Name = treeID; //var treeInfoHashKey = treeInfo.GetHashCode(); //AllTreeLookups.TryAdd(treeInfoHashKey, treeInfo); string treeID = string.Format("lookupTree_{0}", Id); ///we must new from static instance to set info itself var info = treeInfo.DeepCopy <TreeInfo>(); info.Name = treeID; var treeInfoKey = string.Format("{0}_{1}", treeInfo.GetHashCode(), treeID); AllTreeLookups.TryAdd(treeInfoKey, info); var lookupInfo = new Lookup.Tree { Title = title, LookupName = Id, TreeID = treeID, ViewModel = typeof(TModel).AssemblyQualifiedName, ViewInfoKey = treeInfoKey, UseMultiSelect = false, PropertyNameForDisplay = treeInfo.DataTextField, PropertyNameForBinding = propertyNameForBinding }; //-----create lookup---- containerState.InnerHtml = textbox.ToHtmlString() + hiddenValue + CreatLookupButton(lookupInfo); container.InnerHtml = containerState.ToString(); return(MvcHtmlString.Create(container.ToString())); }