コード例 #1
0
        public static MvcHtmlString AuthLanguageSelect <TModel>(this HtmlHelper <TModel> html)
        {
            IEnumerable <Language> languages = GlobalizationManager.Provider.Languages;

            if (languages.Count() < 2)
            {
                return(new MvcHtmlString(String.Empty));
            }

            TagBuilder dropdown          = BootstrapExtensions.FormLanguagesDropdown(html);
            UrlHelper  urlHelper         = new UrlHelper(html.ViewContext.RequestContext);
            TagBuilder languageContainer = new TagBuilder("div");
            TagBuilder currentLang       = new TagBuilder("span");
            TagBuilder languageImg       = new TagBuilder("img");
            TagBuilder caret             = new TagBuilder("span");
            TagBuilder addon             = CreateAddon("fa-flag");

            languageImg.MergeAttribute("alt", String.Empty);
            currentLang.AddCssClass("current-language");
            caret.AddCssClass("caret");

            languageImg.MergeAttribute("src", urlHelper.Content(String.Format("~/Images/Flags/{0}.gif", GlobalizationManager.Provider.CurrentLanguage.Abbrevation)));
            currentLang.InnerHtml = languageImg.ToString(TagRenderMode.SelfClosing) + GlobalizationManager.Provider.CurrentLanguage.Name;

            languageContainer.AddCssClass("language-container dropdown-toggle");
            languageContainer.InnerHtml += currentLang + caret.ToString();
            languageContainer.MergeAttribute("data-toggle", "dropdown");

            return(new MvcHtmlString(String.Format("{0}{1}{2}", addon, languageContainer, dropdown)));
        }
コード例 #2
0
        public static MvcHtmlString LanguageLink(this HtmlHelper html)
        {
            if (GlobalizationManager.Provider.Languages.Count() < 2)
            {
                return(new MvcHtmlString(String.Empty));
            }

            TagBuilder dropdown = BootstrapExtensions.FormLanguagesDropdown(html);
            TagBuilder span     = new TagBuilder("span");
            TagBuilder action   = new TagBuilder("a");
            TagBuilder icon     = new TagBuilder("i");

            action.MergeAttribute("data-toggle", "dropdown");
            action.AddCssClass("dropdown-toggle");
            icon.AddCssClass("fa fa-flag");
            span.AddCssClass("caret");

            action.InnerHtml = String.Format("{0}{1}{2}", icon, ResourceProvider.GetActionTitle("Language"), span);

            return(new MvcHtmlString(String.Format("{0}{1}", action, dropdown)));
        }