Ejemplo n.º 1
0
        public static MvcHtmlString DynamicLink(this HtmlHelper helper, LinkAction action, string id, string caption, object viewData = null, string href = null)
        {
            href = HtmlHelpers.ActionToCommand(action, href);

            TagBuilder tag = new TagBuilder("a");

            tag.Attributes.Add("id", id);
            tag.Attributes.Add("href", href);
            tag.SetInnerText(caption);

            RouteValueDictionary htmlAttributes;
            RouteValueDictionary viewDataObj = HtmlHelper.AnonymousObjectToHtmlAttributes(viewData);

            if (viewDataObj.ContainsKey("htmlAttributes"))
            {
                htmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(viewDataObj["htmlAttributes"]);
            }
            else
            {
                htmlAttributes = viewDataObj;
            }

            foreach (var attr in viewDataObj)
            {
                tag.Attributes.Add(attr.Key, attr.Value.ToString());
            }

            return(tag.ToMvcHtmlString(TagRenderMode.Normal));
        }
Ejemplo n.º 2
0
        public MvcHtmlString HttpMethodOverride(string httpMethod)
        {
            if (String.IsNullOrEmpty(httpMethod))
            {
                throw new ArgumentException(MvcResources.Common_NullOrEmpty, "httpMethod");
            }
            if (
                String.Equals(httpMethod, "GET", StringComparison.OrdinalIgnoreCase) ||
                String.Equals(httpMethod, "POST", StringComparison.OrdinalIgnoreCase)
                )
            {
                throw new ArgumentException(
                          MvcResources.HtmlHelper_InvalidHttpMethod,
                          "httpMethod"
                          );
            }

            TagBuilder tagBuilder = new TagBuilder("input");

            tagBuilder.Attributes["type"]  = "hidden";
            tagBuilder.Attributes["name"]  = HttpRequestExtensions.XHttpMethodOverrideKey;
            tagBuilder.Attributes["value"] = httpMethod;

            return(tagBuilder.ToMvcHtmlString(TagRenderMode.SelfClosing));
        }
        public static MvcHtmlString DynamicActionLink <TModel>(this HtmlHelper <TModel> helper, string fieldId, string name, string type, object viewData = null, bool nullable = false, bool readOnly = false, bool disabled = false, bool visible = true)
        {
            DynamicComponentBase <TModel> dynamicComponent = new DynamicComponentBase <TModel>(helper, fieldId, name, type, viewData, nullable, readOnly, disabled, visible);

            TagBuilder tagInput = new TagBuilder("");

            return(tagInput.ToMvcHtmlString(TagRenderMode.SelfClosing));
        }
Ejemplo n.º 4
0
        public MvcHtmlString AntiForgeryToken(string salt, string domain, string path)
        {
            string formValue = GetAntiForgeryTokenAndSetCookie(salt, domain, path);
            string fieldName = AntiForgeryData.GetAntiForgeryTokenName(null);

            TagBuilder builder = new TagBuilder("input");

            builder.Attributes["type"]  = "hidden";
            builder.Attributes["name"]  = fieldName;
            builder.Attributes["value"] = formValue;
            return(builder.ToMvcHtmlString(TagRenderMode.SelfClosing));
        }
Ejemplo n.º 5
0
        public static MvcHtmlString RenderRazorScripts(this HtmlHelper helper)
        {
            //Injetar os Scripts em uma lista...
            //Executar um método que irá obter essa lista e injetar no html
            //((HttpResponseWrapper)((HttpContextWrapper)helper.ViewContext.HttpContext).Response).Output.Write("<script id=\"scripts_razor\" type=\"text/javascript\"></script>");
            string ret = "";

            foreach (var key in razorScripts.Keys)
            {
                TagBuilder tagScript = new TagBuilder("script");
                tagScript.Attributes.Add("name", $"js-{key}");
                tagScript.Attributes.Add("type", "text/javascript");
                tagScript.InnerHtml = razorScripts[key];
                ret += tagScript.ToMvcHtmlString(TagRenderMode.Normal).ToString();
            }

            return(new MvcHtmlString(ret));
        }
        public static MvcHtmlString DynamicButton(this HtmlHelper helper, LinkAction action, string id, string caption, bool printable = true, object viewData = null, string function = null)
        {
            function = HtmlHelpers.ActionToCommand(action, function);

            TagBuilder tag = new TagBuilder("input");

            tag.Attributes.Add("type", "button");
            tag.Attributes.Add("id", id);
            tag.Attributes.Add("value", caption);
            tag.Attributes.Add("onClick", function);

            RouteValueDictionary htmlAttributes;
            RouteValueDictionary viewDataObj = HtmlHelper.AnonymousObjectToHtmlAttributes(viewData);

            if (viewDataObj.ContainsKey("htmlAttributes"))
            {
                htmlAttributes = HtmlHelper.AnonymousObjectToHtmlAttributes(viewDataObj["htmlAttributes"]);
            }
            else
            {
                htmlAttributes = viewDataObj;
            }

            tag.MergeAttributeValue("class", "btn", true);
            if (!printable)
            {
                tag.MergeAttributeValue("class", "d-print-none", true);
            }

            foreach (var attr in htmlAttributes)
            {
                tag.Attributes.Add(attr.Key, attr.Value.ToString());
            }

            return(tag.ToMvcHtmlString(TagRenderMode.SelfClosing));
        }