public static MvcHtmlString TypeaheadFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, IEnumerable source, object htmlAttributes = null)
        {
            var option = new TypeaheadOption();

            option.Source(source);
            return(html.TypeaheadFor(expression, option, htmlAttributes));
        }
        public static MvcHtmlString TypeaheadFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, TypeaheadOption option, object htmlAttributes = null)
        {
            var metadata      = ModelMetadata.FromLambdaExpression(expression, html.ViewData);
            var htmlFieldName = ExpressionHelper.GetExpressionText(expression);
            var id            = html.ViewData.TemplateInfo.GetFullHtmlFieldId(htmlFieldName);
            var name          = html.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName);
            var value         = (metadata.Model ?? "").ToString();
            var txtValue      = "";

            option.Dictionary.TryGetValue(value, out txtValue);
            var displayName = metadata.DisplayName ?? metadata.PropertyName ?? htmlFieldName.Split('.').Last();
            var mergAttr    = ComponentUtility.MergeAttributes(htmlAttributes, new { id = id + "_typeahead", @class = "form-control", placeholder = displayName, autocomplete = "off" });
            var textbox     = html.TextBox(name + "_typeahead", txtValue, mergAttr);
            var hidden      = html.HiddenFor(expression);

            html.ScriptFileSingle(@"<script src=""" + ComponentUtility.GetWebResourceUrl(typeahead_js) + @"""></script>");
            option.OnSelect(@"function(item) {
                            if ( item.value != ""-21"") {
                                $(""#" + id + @""").val(item.value).trigger('change').valid();
                            }
                        }");
            html.Script(@"
            <script>
                $(function(){
                    $(""#" + id + @"_typeahead"").typeahead(" + option.RenderOptions() + @")
                    .keypress(function(){
                        $(""#" + id + @""").val('').trigger('change').valid();
                    });
                });
            </script>");
            return(MvcHtmlString.Create(textbox.ToHtmlString() + hidden.ToHtmlString()));
        }
 public static MvcHtmlString TypeaheadFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, Dictionary <int, string> source, TypeaheadOption option, object htmlAttributes = null)
 {
     option.Source(source);
     return(html.TypeaheadFor(expression, option, htmlAttributes));
 }
        public static MvcHtmlString BsTypeaheadFor <TModel, TValue>(this HtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, Dictionary <int, string> source, TypeaheadOption option, string icon = null, ComponentDirection?dir = null, int lable_col = 2, int editor_col = 4, object htmlAttribute = null)
        {
            string displayName = null;

            SetVariables(html, expression, ref displayName, out string style, out string dirName, out string label, out string validator, out object value, lable_col, dir);
            var attributes = ComponentUtility.MergeAttributes(htmlAttribute, new { @class = "form-control", placeholder = displayName, dir = dirName, style = style });
            var editor     = html.TypeaheadFor(expression, source, option, attributes);
            var result     = SetTemplate(label, icon, editor_col, validator, editor.ToHtmlString(), dirName);

            return(MvcHtmlString.Create(result));
        }