public static void EndForm(this HtmlHelper This)
        {
            var fd = This.GetFormData();

            if (fd.currentForm != null)
            {
                if (fd.FormFields != null)
                {
                    string fields = string.Join(",", fd.FormFields.ToArray());

                    var tag = new TagBuilder("input");
                    tag.AddAttribute("type", "hidden");
                    tag.AddAttribute("name", "_Manos_Mvc_FormFields");
                    tag.AddAttribute("value", md5.Calculate(This.Context.Application.ServerKey + fields) + "/" + fields);

                    This.Output.Write(tag.Render());
                    This.Output.Write("\n");

                    fd.FormFields = null;
                }

                This.Output.Write("</form>");

                var old = fd.currentForm;
                fd.currentForm = old.outer;
                old.Close();
            }
        }
        public static HtmlForm BeginForm(this HtmlHelper This)
        {
            var fd = This.GetFormData();

            // Create a new form
            fd.currentForm = new HtmlForm(This, fd.currentForm);

            var tag = new TagBuilder("form");

            tag.AddAttribute("method", "post");
            tag.AddAttribute("action", This.Context.ManosContext.Request.Path);

            This.Output.Write(tag.RenderOpening());
            This.Output.Write("\n");

            return fd.currentForm;
        }
        public static HtmlString CheckBox(this HtmlHelper This, string key, object value = null, object htmlAttributes = null)
        {
            This.RegisterFormField(key);

            var tag = new TagBuilder("input");

            tag.AddAttribute("type", "checkbox");
            tag.AddAttribute("name", key);
            tag.AddAttribute("id", key);
            tag.AddAttribute("value", "true");
            tag.AddAttributes(htmlAttributes);

            if ((bool)Convert.ChangeType(This.ResolveFormValue(key, value), typeof(bool)))
            {
                tag.AddAttribute("checked", "checked");
            }

            if (!This.Context.ModelState.IsFieldValid(key))
                tag.AddClass("model_validation_error");

            return new HtmlString(tag.Render());
        }
        public static HtmlString Input(this HtmlHelper This, string type, string key, object value = null, object htmlAttributes = null)
        {
            This.RegisterFormField(key);

            var tag = new TagBuilder("input");

            tag.AddAttribute("type", type);
            tag.AddAttribute("name", key);
            tag.AddAttribute("id", key);
            if (type != "password")
                tag.AddAttribute("value", This.ResolveFormValue(key, value));
            tag.AddAttributes(htmlAttributes);

            if (!This.Context.ModelState.IsFieldValid(key))
                tag.AddClass("model_validation_error");

            return new HtmlString(tag.Render());
        }
        public static HtmlString TextArea(this HtmlHelper This, string key, object value = null, object htmlAttributes = null)
        {
            This.RegisterFormField(key);

            var tag = new TagBuilder("textarea");

            tag.AddAttribute("name", key);
            tag.AddAttribute("id", key);
            tag.AddAttribute("cols", 40);
            tag.AddAttribute("rows", 4);

            tag.AddAttributes(htmlAttributes);
            if (!This.Context.ModelState.IsFieldValid(key))
                tag.AddClass("model_validation_error");

            var text = This.ResolveFormValue(key, value);
            if (text != null)
                tag.AddContent(text.ToString());

            tag.AlwaysUseFullForm = true;

            return new HtmlString(tag.Render());
        }
        public static HtmlString RadioButton(this HtmlHelper This, string key, object button_value, object form_value = null, object htmlAttributes = null)
        {
            var fd = This.GetFormData();

            if (fd.RadioButtonIndicies==null)
            {
                fd.RadioButtonIndicies = new Dictionary<string, int>();
            }

            int index;
            if (!fd.RadioButtonIndicies.TryGetValue(key, out index))
            {
                index = 0;
            }
            index++;
            fd.RadioButtonIndicies[key] = index;
            string id = key + index.ToString();

            This.RegisterFormField(key);

            form_value = This.ResolveFormValue(key, form_value);

            fd.LastFormField = id;

            var tag = new TagBuilder("input");

            tag.AddAttribute("type", "radio");
            tag.AddAttribute("name", key);
            tag.AddAttribute("id", id);
            tag.AddAttribute("value", button_value);
            tag.AddAttributes(htmlAttributes);

            if (button_value.Equals(form_value))
            {
                tag.AddAttribute("checked", "checked");
            }

            if (!This.Context.ModelState.IsFieldValid(key))
                tag.AddClass("model_validation_error");

            return new HtmlString(tag.Render());
        }