/// <summary> /// render select list 2 columns /// </summary> /// <param name="html"></param> /// <param name="name"></param> /// <param name="selectList"></param> /// <param name="attribute"></param> /// <returns></returns> public static String SelectList2Column(this HtmlHelper html, String name, IEnumerable <SelectListItem> selectList, Object attribute, int width) { var items = Json.EncodeDictionary(selectList.ToDictionary(item => item.Value, item => item.Text)); var selectedItems = Json.Encode(selectList.Where(item => item.Selected).Select(item => item.Value).ToArray()); var itemsStr = items.Substring(0, items.Length); var selectedItemsStr = selectedItems.Substring(0, selectedItems.Length); var htmlID = name.Replace(".", "_") + "Container"; var containertag = new TagBuilder("div"); containertag.MergeAttribute("id", htmlID); var script = String.Format(@"new SelectList2Column({{ htmlID: {0}, name: {1}, items: {2}, selectedItems: {3}, width: {4} }}).render();", Json.Encode(htmlID), Json.Encode(name), itemsStr, selectedItemsStr, width ); return(containertag.ToString() + Javascript.AddToJavascriptTag(script)); }
/// <summary> /// auto complete for an input /// </summary> /// <param name="html"></param> /// <param name="HtmlID"></param> /// <param name="option"></param> /// <returns></returns> public static String AutoCompleteFor(this HtmlHelper html, String HtmlID, AutoCompleteOption option) { var jsOption = option.ToJSON(); var js = String.Format(@"$(""#{0}"").autocomplete(""{1}"", {2});", HtmlID, option.URL, jsOption); var js1 = ""; if (option.Result != null) { js1 = String.Format(@"$(""#{0}"").result(function(event, data, formatted) {{ var info; eval(""info = ""+formatted);{1}}} );", HtmlID, option.Result); } else if (option.ResultFunc != null) { js1 = String.Format(@"$(""#{0}"").result({1});", HtmlID, option.ResultFunc); } return(Javascript.AddToJavascriptTag(js + js1)); }