using System.Collections.Generic; using System.Text; using System.Web.Mvc; using System.Web.Mvc.Html; namespace Kreta.Web.Helpers { public static class FormExtensions { public static MvcForm KretaForm(this HtmlHelper htmlHelper, string name, Dictionary htmlAttributes = null) { if (htmlAttributes == null) htmlAttributes = new Dictionary(); htmlAttributes.Add("id", name); htmlAttributes.Add("onsubmit", "return false"); var mvcForm = htmlHelper.BeginForm(null, null, FormMethod.Get, htmlAttributes); var formName = "#" + name; StringBuilder sb = new StringBuilder(); sb.Append(""); sb.AppendFormat("", formName); htmlHelper.ViewContext.Writer.Write(sb.ToString()); sb.Append(""); return mvcForm; } public static MvcForm KretaForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, string name, Dictionary htmlAttributes = null) { if (htmlAttributes == null) htmlAttributes = new Dictionary(); htmlAttributes.Add("id", name); var mvcForm = htmlHelper.BeginForm(actionName, controllerName, method, htmlAttributes); var formName = "#" + name; StringBuilder sb = new StringBuilder(); sb.Append(""); sb.AppendFormat("", formName); htmlHelper.ViewContext.Writer.Write(sb.ToString()); return mvcForm; } } }