Exemplo n.º 1
0
        public static IHtmlContent TypeaheadMasterFor <TModel, TValue>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, IEnumerable <string> source, object htmlAttributes = null)
        {
            var option = new TypeaheadMasterOption();

            if (source != null)
            {
                option.DataSetSource(source);
            }

            return(html.TypeaheadMasterFor(expression, option, htmlAttributes));
        }
Exemplo n.º 2
0
        //public static IHtmlContent TypeaheadMasterFor<TModel, TValue>(this IHtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, Dictionary<int, string> source, TypeaheadMasterOption option, object htmlAttributes = null)
        //{
        //    option.DataSetSource(source);
        //    return html.TypeaheadMasterFor(expression, option, htmlAttributes);
        //}
        //public static IHtmlContent TypeaheadMasterFor<TModel, TValue>(this IHtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression, IEnumerable source, TypeaheadMasterOption option, object htmlAttributes = null)
        //{
        //    option.DataSetSource(source);
        //    return html.TypeaheadMasterFor(expression, option, htmlAttributes);
        //}

        public static IHtmlContent TypeaheadMasterFor <TModel, TValue>(this IHtmlHelper <TModel> html, Expression <Func <TModel, TValue> > expression, TypeaheadMasterOption option, object htmlAttributes = null)
        {
            var metadata      = html.GetModelExplorer(expression);
            var htmlFieldName = html.FieldNameFor(expression);
            var id            = html.FieldIdFor(expression);
            var displayName   = metadata.Metadata.DisplayName ?? metadata.Metadata.PropertyName ?? htmlFieldName.Split('.').Last();
            var mergAttr      = ComponentUtility.MergeAttributes(htmlAttributes, new { @class = "form-control", placeholder = displayName, autocomplete = "off" });
            var editor        = html.TextBoxFor(expression, mergAttr);

            html.StyleOnce(ComponentUtility.GetCssTag(typeahead_css, null));
            html.ScriptOnce(ComponentUtility.GetCssTag(typeahead_bundle_js, typeahead_bundle_js_cdn));
            html.Script(@"
            <script>
                $(function(){
                    $(""#" + id + @""").typeahead(" + option.RenderOptions() + @",
                    " + option.RenderDataSetOptions() + @");
                });
            </script>");
            return(editor);
        }