Пример #1
0
        public string ToHtmlString()
        {
            var mergedHtmlAttributes = _htmlAttributes;

            if (!string.IsNullOrEmpty(_id))
            {
                mergedHtmlAttributes.AddIfNotExist("id", _id);
            }
            if (_disabled)
            {
                mergedHtmlAttributes.AddOrMergeCssClass("class", "disabled");
            }

            var linkBuilder = new TagBuilder("a");

            linkBuilder.MergeAttributes(mergedHtmlAttributes);
            linkBuilder.MergeAttribute("href", _url);

            if (_iconPrepend != string.Empty || _iconAppend != string.Empty || !string.IsNullOrEmpty(_iconPrependCustomClass) || !string.IsNullOrEmpty(_iconAppendCustomClass))
            {
                var iPrependString = string.Empty;
                var iAppendString  = string.Empty;

                if (_iconPrepend != string.Empty)
                {
                    iPrependString = new BootstrapIcon(_iconPrepend, _iconPrependIsWhite).ToHtmlString() + " ";
                }
                if (_iconAppend != string.Empty)
                {
                    iAppendString = " " + new BootstrapIcon(_iconAppend, _iconAppendIsWhite).ToHtmlString();
                }
                if (!string.IsNullOrEmpty(_iconPrependCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(_iconPrependCustomClass);
                    iPrependString = i.ToString(TagRenderMode.Normal) + " ";
                }
                if (!string.IsNullOrEmpty(_iconAppendCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(_iconAppendCustomClass);
                    iAppendString = " " + i.ToString(TagRenderMode.Normal);
                }

                _linkText = iPrependString + _linkText + iAppendString;
            }

            linkBuilder.InnerHtml = _linkText;

            string input = linkBuilder.ToString(TagRenderMode.Normal);

            if (!string.IsNullOrEmpty(_wrapTag))
            {
                input = string.Format("<{0}>{1}</{0}>", _wrapTag, input);
            }

            return(MvcHtmlString.Create(input).ToString());
        }
Пример #2
0
        public virtual string ToHtmlString()
        {
            var input = new TagBuilder("button");

            input.Attributes.Add("type", _model.type);
            if (!string.IsNullOrEmpty(_model.name))
            {
                input.Attributes.Add("name", _model.name);
            }
            if (!string.IsNullOrEmpty(_model.id))
            {
                input.Attributes.Add("id", _model.id);
            }
            if (!string.IsNullOrEmpty(_model.value))
            {
                input.Attributes.Add("value", _model.value);
            }
            if (_model.tooltip != null)
            {
                _model.htmlAttributes.MergeHtmlAttributes(_model.tooltip.ToDictionary());
            }
            if (_model.popover != null)
            {
                _model.htmlAttributes.MergeHtmlAttributes(_model.popover.ToDictionary());
            }
            input.MergeAttributes(_model.htmlAttributes.FormatHtmlAttributes());
            input.AddCssClass(BootstrapHelper.GetClassForButtonSize(_model.size));
            input.AddCssClass(BootstrapHelper.GetClassForButtonColor(_model.color));
            if (_model.buttonBlock)
            {
                input.AddCssClass("btn-block");
            }
            if (_model.isShiny)
            {
                input.AddCssClass("shiny");
            }
            if (_model.circular)
            {
                input.AddCssClass("btn-circle");
            }
            if (_model.iconOnly)
            {
                input.AddCssClass("icon-only");
            }
            if (_model.labeled)
            {
                input.AddCssClass("btn-labeled");
            }
            if (_model.isDropDownToggle)
            {
                input.AddCssClass("dropdown-toggle");
                input.AddOrMergeAttribute("data-toggle", "dropdown");
            }
            if (_model.disabled)
            {
                input.AddCssClass("disabled");
                input.AddOrMergeAttribute("disabled", "");
            }

            if (!string.IsNullOrEmpty(_model.loadingText))
            {
                input.AddOrMergeAttribute("data-loading-text", _model.loadingText);
            }
            input.AddCssClass("btn");

            if (_withCaret)
            {
                if (!string.IsNullOrEmpty(_model.text))
                {
                    _model.text += " ";
                }
                _model.text += "<span class='caret'></span>";
            }

            if (_model.iconPrepend != String.Empty || _model.iconAppend != String.Empty || !string.IsNullOrEmpty(_model.iconPrependCustomClass) || !string.IsNullOrEmpty(_model.iconAppendCustomClass))
            {
                var iPrependString  = string.Empty;
                var iAppendString   = string.Empty;
                var iconLabelString = "";
                if (_model.labeled)
                {
                    iconLabelString = " btn-label";
                }
                if (_model.iconPrepend != String.Empty)
                {
                    iPrependString = new BootstrapIcon(_model.iconPrepend + iconLabelString, _model.iconPrependIsWhite).ToHtmlString();
                }
                if (_model.iconAppend != String.Empty)
                {
                    iAppendString = new BootstrapIcon(_model.iconAppend + " right" + iconLabelString, _model.iconAppendIsWhite).ToHtmlString();
                }
                if (!string.IsNullOrEmpty(_model.iconPrependCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(_model.iconPrependCustomClass);
                    iPrependString = i.ToString(TagRenderMode.Normal);
                }
                if (!string.IsNullOrEmpty(_model.iconAppendCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(_model.iconAppendCustomClass);
                    iAppendString = i.ToString(TagRenderMode.Normal);
                }

                _model.text =
                    iPrependString +
                    (!string.IsNullOrEmpty(iPrependString) && (!string.IsNullOrEmpty(_model.text) || !string.IsNullOrEmpty(iAppendString)) ? " " : "") +
                    _model.text +
                    (!string.IsNullOrEmpty(iAppendString) && (!string.IsNullOrEmpty(_model.text) || !string.IsNullOrEmpty(iPrependString)) ? " " : "") +
                    iAppendString;
            }

            input.InnerHtml = _model.text;
            return(input.ToString());
        }
Пример #3
0
        public string ToHtmlString()
        {
            var mergedHtmlAttributes = _htmlAttributes;

            if (!string.IsNullOrEmpty(_id))
            {
                mergedHtmlAttributes.AddIfNotExist("id", _id);
            }

            if (_isDropDownToggle)
            {
                mergedHtmlAttributes.AddOrMergeCssClass("class", "dropdown-toggle");
                mergedHtmlAttributes.AddIfNotExist("data-toggle", "dropdown");
            }
            if (_disabled)
            {
                mergedHtmlAttributes.AddOrMergeCssClass("class", "disabled");
            }
            if (!string.IsNullOrEmpty(_title))
            {
                mergedHtmlAttributes.AddOrReplace("title", _title);
            }

            var input          = string.Empty;
            var iPrependString = string.Empty;
            var iAppendString  = string.Empty;

            if (_iconPrepend != string.Empty || _iconAppend != string.Empty || !string.IsNullOrEmpty(_iconPrependCustomClass) || !string.IsNullOrEmpty(_iconAppendCustomClass))
            {
                if (_iconPrepend != string.Empty)
                {
                    iPrependString = new BootstrapIcon(_iconPrepend, _iconPrependIsWhite).ToHtmlString() + " ";
                }
                if (_iconAppend != string.Empty)
                {
                    iAppendString = " " + new BootstrapIcon(_iconAppend, _iconAppendIsWhite).ToHtmlString();
                }
                if (!string.IsNullOrEmpty(_iconPrependCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(_iconPrependCustomClass);
                    iPrependString = i.ToString(TagRenderMode.Normal) + " ";
                }
                if (!string.IsNullOrEmpty(_iconAppendCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(_iconAppendCustomClass);
                    iAppendString = " " + i.ToString(TagRenderMode.Normal);
                }
                _linkText = "{0}" + _linkText + "{1}";
            }

            var requestedController = "";
            var requestedAction     = "";
            var requestedArea       = "";

            switch (_actionTypePassed)
            {
            case ActionTypePassed.HtmlRegular:
                requestedArea       = _routeValues != null && _routeValues.ContainsKey("area") ? _routeValues["area"].ToString() : html.ViewContext.RouteData.DataTokens.ContainsKey("area") ? html.ViewContext.RouteData.DataTokens["area"].ToString() : string.Empty;
                requestedController = string.IsNullOrEmpty(_controllerName) ? html.ViewContext.RouteData.GetRequiredString("controller") : _controllerName;
                requestedAction     = _actionName;
                input = html.ActionLink(_linkText, _actionName, _controllerName, _protocol, _hostName, _fragment, _routeValues, mergedHtmlAttributes).ToHtmlString();
                break;

            case ActionTypePassed.HtmlActionResult:
                requestedArea       = _result.GetRouteValueDictionary().ContainsKey("area") ? _result.GetRouteValueDictionary()["area"].ToString() : string.Empty;
                requestedController = _result.GetRouteValueDictionary()["controller"].ToString();
                requestedAction     = _result.GetRouteValueDictionary()["action"].ToString();
                input = html.ActionLink(_linkText, _result, mergedHtmlAttributes, _protocol, _hostName, _fragment).ToHtmlString();
                break;

            case ActionTypePassed.HtmlTaskResult:
                requestedArea       = _taskResult.Result.GetRouteValueDictionary().ContainsKey("area") ? _taskResult.Result.GetRouteValueDictionary()["area"].ToString() : string.Empty;
                requestedController = _taskResult.Result.GetRouteValueDictionary()["controller"].ToString();
                requestedAction     = _taskResult.Result.GetRouteValueDictionary()["action"].ToString();
                input = html.ActionLink(_linkText, _taskResult, mergedHtmlAttributes, _protocol, _hostName, _fragment).ToHtmlString();
                break;

            case ActionTypePassed.AjaxRegular:
                requestedArea       = _routeValues != null && _routeValues.ContainsKey("area") ? _routeValues["area"].ToString() : ajax.ViewContext.RouteData.DataTokens.ContainsKey("area") ? ajax.ViewContext.RouteData.DataTokens["area"].ToString() : string.Empty;
                requestedController = string.IsNullOrEmpty(_controllerName) ? ajax.ViewContext.RouteData.GetRequiredString("controller") : _controllerName;
                requestedAction     = _actionName;
                input = ajax.ActionLink(_linkText, _actionName, _controllerName, _protocol, _hostName, _fragment, _routeValues, _ajaxOptions, mergedHtmlAttributes).ToHtmlString();
                break;

            case ActionTypePassed.AjaxActionResult:
                requestedArea       = _result.GetRouteValueDictionary().ContainsKey("area") ? _result.GetRouteValueDictionary()["area"].ToString() : string.Empty;
                requestedController = _result.GetRouteValueDictionary()["controller"].ToString();
                requestedAction     = _result.GetRouteValueDictionary()["action"].ToString();
                input = ajax.ActionLink(_linkText, _result, _ajaxOptions, mergedHtmlAttributes).ToHtmlString();
                break;

            case ActionTypePassed.AjaxTaskResult:
                requestedArea       = _taskResult.Result.GetRouteValueDictionary().ContainsKey("area") ? _taskResult.Result.GetRouteValueDictionary()["area"].ToString() : string.Empty;
                requestedController = _taskResult.Result.GetRouteValueDictionary()["controller"].ToString();
                requestedAction     = _taskResult.Result.GetRouteValueDictionary()["action"].ToString();
                input = ajax.ActionLink(_linkText, _taskResult, _ajaxOptions, mergedHtmlAttributes).ToHtmlString();
                break;
            }

            input = string.Format(input, iPrependString, iAppendString);

            if (!string.IsNullOrEmpty(_wrapTag))
            {
                var currentAction     = string.Empty;
                var currentController = string.Empty;
                var currentArea       = string.Empty;
                switch (_actionTypePassed)
                {
                case ActionTypePassed.HtmlRegular:
                case ActionTypePassed.HtmlActionResult:
                case ActionTypePassed.HtmlTaskResult:
                    currentAction     = html.ViewContext.RouteData.GetRequiredString("action");
                    currentController = html.ViewContext.RouteData.GetRequiredString("controller");
                    currentArea       = html.ViewContext.RouteData.DataTokens.ContainsKey("area") ? html.ViewContext.RouteData.DataTokens["area"].ToString() : string.Empty;
                    break;

                case ActionTypePassed.AjaxRegular:
                case ActionTypePassed.AjaxActionResult:
                case ActionTypePassed.AjaxTaskResult:
                    currentAction     = ajax.ViewContext.RouteData.GetRequiredString("action");
                    currentController = ajax.ViewContext.RouteData.GetRequiredString("controller");
                    currentArea       = ajax.ViewContext.RouteData.DataTokens.ContainsKey("area") ? ajax.ViewContext.RouteData.DataTokens["area"].ToString() : string.Empty;
                    break;
                }

                var classActive = "";
                if (_wrapTagControllerAware && currentArea == requestedArea && currentController == requestedController)
                {
                    classActive = @" class=""active""";
                }
                if (_wrapTagControllerAndActionAware && currentArea == requestedArea && currentController == requestedController && currentAction == requestedAction)
                {
                    classActive = @" class=""active""";
                }
                input = string.Format("<{0}{1}>{2}</{0}>", _wrapTag, classActive, input);
            }

            return(MvcHtmlString.Create(input).ToString());
        }
Пример #4
0
        public override string ToHtmlString()
        {
            var mergedHtmlAttributes = _model.htmlAttributes;

            mergedHtmlAttributes.AddOrMergeCssClass("class", "btn");
            if (!string.IsNullOrEmpty(_model.id))
            {
                mergedHtmlAttributes.AddIfNotExist("id", _model.id);
            }

            mergedHtmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForButtonSize(_model.size));
            mergedHtmlAttributes.AddOrMergeCssClass("class", BootstrapHelper.GetClassForButtonColor(_model.color));

            if (_model.buttonBlock)
            {
                mergedHtmlAttributes.AddOrMergeCssClass("class", "btn-block");
            }
            if (_model.isDropDownToggle)
            {
                mergedHtmlAttributes.AddOrMergeCssClass("class", "dropdown-toggle");
                mergedHtmlAttributes.AddIfNotExist("data-toggle", "dropdown");
            }
            if (_model.disabled)
            {
                mergedHtmlAttributes.AddOrMergeCssClass("class", "disabled");
            }
            if (!string.IsNullOrEmpty(_model.loadingText))
            {
                mergedHtmlAttributes.AddOrReplace("data-loading-text", _model.loadingText);
            }
            if (!string.IsNullOrWhiteSpace(_title))
            {
                mergedHtmlAttributes.Add("title", _title);
            }

            var input = string.Empty;

            if (_model.iconPrepend != string.Empty || _model.iconAppend != string.Empty || !string.IsNullOrEmpty(_model.iconPrependCustomClass) || !string.IsNullOrEmpty(_model.iconAppendCustomClass))
            {
                var iPrependString = string.Empty;
                var iAppendString  = string.Empty;

                if (_model.iconPrepend != string.Empty)
                {
                    iPrependString = new BootstrapIcon(_model.iconPrepend, _model.iconPrependIsWhite).ToHtmlString();
                }
                if (_model.iconAppend != string.Empty)
                {
                    iAppendString = new BootstrapIcon(_model.iconAppend, _model.iconAppendIsWhite).ToHtmlString();
                }
                if (!string.IsNullOrEmpty(_model.iconPrependCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(_model.iconPrependCustomClass);
                    iPrependString = i.ToString(TagRenderMode.Normal);
                }
                if (!string.IsNullOrEmpty(_model.iconAppendCustomClass))
                {
                    var i = new TagBuilder("i");
                    i.AddCssClass(_model.iconAppendCustomClass);
                    iAppendString = i.ToString(TagRenderMode.Normal);
                }

                var combined =
                    iPrependString +
                    (!string.IsNullOrEmpty(iPrependString) && (!string.IsNullOrEmpty(_model.text) || !string.IsNullOrEmpty(iAppendString)) ? " " : "") +
                    _model.text +
                    (!string.IsNullOrEmpty(iAppendString) && (!string.IsNullOrEmpty(_model.text) || !string.IsNullOrEmpty(iPrependString)) ? " " : "") +
                    iAppendString;

                var holder = Guid.NewGuid().ToString();

                input = GenerateActionLink(holder, mergedHtmlAttributes);
                input = input.Replace(holder, combined);
            }
            else
            {
                input = GenerateActionLink(_model.text, mergedHtmlAttributes);
            }

            return(MvcHtmlString.Create(input).ToString());
        }