Esempio n. 1
0
        protected override void WriteSelfStart(System.IO.TextWriter writer)
        {
            var tb = Helper.CreateTagBuilder("form");

            if (Type != FormType.DefaultNone)
            {
                tb.AddCssClass(Type.ToCssClass());
            }
            if (Method != SubmitMethod.Get)
            {
                tb.MergeAttribute("method", Method.ToString().ToLowerInvariant(), true);
            }
            if (Enctype != FormEnctype.NoValue)
            {
                tb.MergeAttribute("enctype", Enctype.ToEnctype(), true);
            }
            if (!string.IsNullOrEmpty(Href))
            {
                tb.MergeAttribute("action", Href, true);
            }

            ApplyCss(tb);
            ApplyAttributes(tb);

            tb.WriteStartTag(writer);
        }
 public MvcForm BeginMvcForm(string url, Enctype enctype, FormMethod method, bool?antiforgery, object htmlAttributes)
 {
     this.htmlHelper.ViewContext.FormContext = new FormContext()
     {
         CanRenderAtEndOfForm = true
     };
     return(this.GenerateMvcForm(url, method, enctype, antiforgery, htmlAttributes));
 }
        public static MvcForm ToMvcForm(this HtmlRouteValueDictionary htmlAttributes, string url,
                                        FormMethod method,
                                        Enctype enctype = Enctype.ApplicationXwwwFormUrlEncoded
                                        )
        {
            //if (!htmlAttributes.ContainsKey(HtmlAttribute.Method.ToStringLower()))
            //    htmlAttributes.Set(HtmlAttribute.Method.ToStringLower(), EnumExtensions.ToStringLower(method));

            //if (!htmlAttributes.ContainsKey(HtmlAttribute.Enctype.ToStringLower()))
            //    htmlAttributes.Set(HtmlAttribute.Enctype.ToStringLower(), enctype.ToLocalization());

            //if (!htmlAttributes.ContainsKey(HtmlAttribute.Action.ToStringLower()))
            //    htmlAttributes.Set(HtmlAttribute.Action.ToStringLower(), url);

            return(new IncodingHtmlHelper(htmlAttributes.HtmlHelper).BeginMvcForm(url, enctype, method, false, htmlAttributes));
        }
        protected virtual MvcForm GenerateMvcForm(string url, FormMethod method, Enctype enctype, bool?antiforgery, object htmlAttributes)
        {
            TagBuilder form = this.GenerateFormCore(this.htmlHelper.ViewContext, url, enctype, HtmlHelper.GetFormMethodString(method), htmlAttributes);

            if (form != null)
            {
                form.TagRenderMode = TagRenderMode.StartTag;
                form.WriteTo(this.htmlHelper.ViewContext.Writer, HtmlEncoder.Default);
            }
            if ((antiforgery.HasValue ? (antiforgery.Value ? 1 : 0) : ((uint)method > 0U ? 1 : 0)) != 0)
            {
                this.htmlHelper.ViewContext.FormContext.EndOfFormContent.Add(this.htmlHelper.AntiForgeryToken());
            }

            return(new MvcForm(htmlHelper.ViewContext, HtmlEncoder.Default));
        }
        public static BeginTag ToBeginForm(this HtmlRouteValueDictionary htmlAttributes, string url,
                                           JqueryAjaxOptions.HttpVerbs method = JqueryAjaxOptions.HttpVerbs.Post,
                                           Enctype enctype = Enctype.ApplicationXwwwFormUrlEncoded
                                           )
        {
            if (!htmlAttributes.ContainsKey(HtmlAttribute.Method.ToStringLower()))
            {
                htmlAttributes.Set(HtmlAttribute.Method.ToStringLower(), method.ToStringLower());
            }

            if (!htmlAttributes.ContainsKey(HtmlAttribute.Enctype.ToStringLower()))
            {
                htmlAttributes.Set(HtmlAttribute.Enctype.ToStringLower(), enctype.ToLocalization());
            }

            if (!htmlAttributes.ContainsKey(HtmlAttribute.Action.ToStringLower()))
            {
                htmlAttributes.Set(HtmlAttribute.Action.ToStringLower(), url);
            }

            return(ToBeginTag(htmlAttributes, HtmlTag.Form));
        }
        public static BeginTag ToBeginForm(this RouteValueDictionary htmlAttributes, HtmlHelper htmlHelper, string url,
                                           HttpVerbs method = HttpVerbs.Post,
                                           Enctype enctype  = Enctype.ApplicationXWWWFormUrlEncoded
                                           )
        {
            if (!htmlAttributes.ContainsKey(HtmlAttribute.Method.ToStringLower()))
            {
                htmlAttributes.Set(HtmlAttribute.Method.ToStringLower(), method.ToStringLower());
            }

            if (!htmlAttributes.ContainsKey(HtmlAttribute.Enctype.ToStringLower()))
            {
                htmlAttributes.Set(HtmlAttribute.Enctype.ToStringLower(), enctype.ToLocalization());
            }

            if (!htmlAttributes.ContainsKey(HtmlAttribute.Action.ToStringLower()))
            {
                htmlAttributes.Set(HtmlAttribute.Action.ToStringLower(), url);
            }

            return(htmlAttributes.ToBeginTag(HtmlTag.Form));
        }
        protected virtual TagBuilder GenerateFormCore(ViewContext viewContext, string action, Enctype enctype, string method, object htmlAttributes)
        {
            if (viewContext == null)
            {
                throw new ArgumentNullException(nameof(viewContext));
            }
            TagBuilder tagBuilder = new TagBuilder("form");
            IDictionary <string, object> dictionaryOrNull = GetHtmlAttributeDictionaryOrNull(htmlAttributes);

            tagBuilder.MergeAttributes <string, object>(dictionaryOrNull);
            string actionKey = nameof(action);

            tagBuilder.MergeAttribute(actionKey, action);
            if (string.IsNullOrEmpty(method))
            {
                method = "post";
            }
            string methodName = nameof(method);

            tagBuilder.MergeAttribute(methodName, method, true);
            string enctypeName = nameof(enctype);

            tagBuilder.MergeAttribute(enctypeName, enctype.ToLocalization(), true);
            return(tagBuilder);
        }