예제 #1
0
        /// <summary>
        ///     Gets the string value for the specified
        /// </summary>
        /// <param name="value">The value.</param>
        public static string ConvertToString(this FormEncType value)
        {
            switch (value)
            {
            case FormEncType.FormUrlEncoded:
                return("application/x-www-form-urlencoded");

            case FormEncType.MultipartData:
                return("multipart/form-data");

            case FormEncType.TextPlain:
                return("text/plain");

            default:
                return("");
            }
        }
예제 #2
0
        public static FlowForm <TModel> BeginFlowForm <TModel>(this HtmlHelper <TModel> helper, string action = null, string controller = null, RouteValueDictionary routeValues = null, FlowFormFormat format = FlowFormFormat.Vertical, bool completed = false, string id = null, FormEncType encType = FormEncType.UrlEncoded, FormMethod method = FormMethod.Post, object htmlAttributes = null)
        {
            var htmlAttrs = ObjectToDictionary(htmlAttributes);

            // Disable unobtrusive JS to stop HTML5 attributes getting printed out
            helper.EnableUnobtrusiveJavaScript(false);

            // Id attribute
            if (id != null)
            {
                htmlAttrs["id"] = id;
            }

            // Class attribute
            if (!htmlAttrs.ContainsKey("class"))
            {
                htmlAttrs["class"] = "";
            }
            var classBuilder = new StringBuilder(htmlAttrs["class"] as string);

            classBuilder.Append(" flow");
            if (format == FlowFormFormat.Horizontal)
            {
                classBuilder.Append(" condensed");
            }
            if (completed)
            {
                classBuilder.Append(" completed");
            }
            if (!helper.ViewData.ModelState.IsValid)
            {
                classBuilder.Append(" erroneous");
            }
            htmlAttrs["class"] = classBuilder.ToString().Trim();

            // Enctype attribute
            htmlAttrs["enctype"] = encType.ToDescription();

            return(new FlowForm <TModel>(helper, helper.BeginForm(action, controller, routeValues, method, htmlAttrs)));
        }
예제 #3
0
 /// <summary>
 /// Sets the enctype attribute.
 /// </summary>
 public static TBuilder EncType <TBuilder>(this TBuilder instance, FormEncType value) where TBuilder : IMvcFormBuilder
 {
     return(instance.EncType(value.ConvertToString()));
 }