Remove excessive shortcut key matching in ToolStrip
[mono.git] / mcs / class / System.Web.Mvc2 / System.Web.Mvc / Html / FormExtensions.cs
1 /* ****************************************************************************\r
2  *\r
3  * Copyright (c) Microsoft Corporation. All rights reserved.\r
4  *\r
5  * This software is subject to the Microsoft Public License (Ms-PL). \r
6  * A copy of the license can be found in the license.htm file included \r
7  * in this distribution.\r
8  *\r
9  * You must not remove this notice, or any other, from this software.\r
10  *\r
11  * ***************************************************************************/\r
12 \r
13 namespace System.Web.Mvc.Html {\r
14     using System.Collections.Generic;\r
15     using System.Web.Routing;\r
16     using System.Globalization;\r
17 \r
18     public static class FormExtensions {\r
19         public static MvcForm BeginForm(this HtmlHelper htmlHelper) {\r
20             // generates <form action="{current url}" method="post">...</form>\r
21             string formAction = htmlHelper.ViewContext.HttpContext.Request.RawUrl;\r
22             return FormHelper(htmlHelper, formAction, FormMethod.Post, new RouteValueDictionary());\r
23         }\r
24 \r
25         public static MvcForm BeginForm(this HtmlHelper htmlHelper, object routeValues) {\r
26             return BeginForm(htmlHelper, null, null, new RouteValueDictionary(routeValues), FormMethod.Post, new RouteValueDictionary());\r
27         }\r
28 \r
29         public static MvcForm BeginForm(this HtmlHelper htmlHelper, RouteValueDictionary routeValues) {\r
30             return BeginForm(htmlHelper, null, null, routeValues, FormMethod.Post, new RouteValueDictionary());\r
31         }\r
32 \r
33         public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName) {\r
34             return BeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(), FormMethod.Post, new RouteValueDictionary());\r
35         }\r
36 \r
37         public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues) {\r
38             return BeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(routeValues), FormMethod.Post, new RouteValueDictionary());\r
39         }\r
40 \r
41         public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues) {\r
42             return BeginForm(htmlHelper, actionName, controllerName, routeValues, FormMethod.Post, new RouteValueDictionary());\r
43         }\r
44 \r
45         public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method) {\r
46             return BeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(), method, new RouteValueDictionary());\r
47         }\r
48 \r
49         public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method) {\r
50             return BeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(routeValues), method, new RouteValueDictionary());\r
51         }\r
52 \r
53         public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method) {\r
54             return BeginForm(htmlHelper, actionName, controllerName, routeValues, method, new RouteValueDictionary());\r
55         }\r
56 \r
57         public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, object htmlAttributes) {\r
58             return BeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(), method, new RouteValueDictionary(htmlAttributes));\r
59         }\r
60 \r
61         public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, IDictionary<string, object> htmlAttributes) {\r
62             return BeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(), method, htmlAttributes);\r
63         }\r
64 \r
65         public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method, object htmlAttributes) {\r
66             return BeginForm(htmlHelper, actionName, controllerName, new RouteValueDictionary(routeValues), method, new RouteValueDictionary(htmlAttributes));\r
67         }\r
68 \r
69         public static MvcForm BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, RouteValueDictionary routeValues, FormMethod method, IDictionary<string, object> htmlAttributes) {\r
70             string formAction = UrlHelper.GenerateUrl(null /* routeName */, actionName, controllerName, routeValues, htmlHelper.RouteCollection, htmlHelper.ViewContext.RequestContext, true /* includeImplicitMvcValues */);\r
71             return FormHelper(htmlHelper, formAction, method, htmlAttributes);\r
72         }\r
73 \r
74         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, object routeValues) {\r
75             return BeginRouteForm(htmlHelper, null /* routeName */, new RouteValueDictionary(routeValues), FormMethod.Post, new RouteValueDictionary());\r
76         }\r
77 \r
78         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, RouteValueDictionary routeValues) {\r
79             return BeginRouteForm(htmlHelper, null /* routeName */, routeValues, FormMethod.Post, new RouteValueDictionary());\r
80         }\r
81 \r
82         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName) {\r
83             return BeginRouteForm(htmlHelper, routeName, new RouteValueDictionary(), FormMethod.Post, new RouteValueDictionary());\r
84         }\r
85 \r
86         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, object routeValues) {\r
87             return BeginRouteForm(htmlHelper, routeName, new RouteValueDictionary(routeValues), FormMethod.Post, new RouteValueDictionary());\r
88         }\r
89 \r
90         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, RouteValueDictionary routeValues) {\r
91             return BeginRouteForm(htmlHelper, routeName, routeValues, FormMethod.Post, new RouteValueDictionary());\r
92         }\r
93 \r
94         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, FormMethod method) {\r
95             return BeginRouteForm(htmlHelper, routeName, new RouteValueDictionary(), method, new RouteValueDictionary());\r
96         }\r
97 \r
98         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, object routeValues, FormMethod method) {\r
99             return BeginRouteForm(htmlHelper, routeName, new RouteValueDictionary(routeValues), method, new RouteValueDictionary());\r
100         }\r
101 \r
102         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, RouteValueDictionary routeValues, FormMethod method) {\r
103             return BeginRouteForm(htmlHelper, routeName, routeValues, method, new RouteValueDictionary());\r
104         }\r
105 \r
106         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, FormMethod method, object htmlAttributes) {\r
107             return BeginRouteForm(htmlHelper, routeName, new RouteValueDictionary(), method, new RouteValueDictionary(htmlAttributes));\r
108         }\r
109 \r
110         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, FormMethod method, IDictionary<string, object> htmlAttributes) {\r
111             return BeginRouteForm(htmlHelper, routeName, new RouteValueDictionary(), method, htmlAttributes);\r
112         }\r
113 \r
114         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, object routeValues, FormMethod method, object htmlAttributes) {\r
115             return BeginRouteForm(htmlHelper, routeName, new RouteValueDictionary(routeValues), method, new RouteValueDictionary(htmlAttributes));\r
116         }\r
117 \r
118         public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, RouteValueDictionary routeValues, FormMethod method, IDictionary<string, object> htmlAttributes) {\r
119             string formAction = UrlHelper.GenerateUrl(routeName, null, null, routeValues, htmlHelper.RouteCollection, htmlHelper.ViewContext.RequestContext, false /* includeImplicitMvcValues */);\r
120             return FormHelper(htmlHelper, formAction, method, htmlAttributes);\r
121         }\r
122 \r
123         public static void EndForm(this HtmlHelper htmlHelper) {\r
124             htmlHelper.ViewContext.Writer.Write("</form>");\r
125             htmlHelper.ViewContext.OutputClientValidation();\r
126         }\r
127 \r
128         private static MvcForm FormHelper(this HtmlHelper htmlHelper, string formAction, FormMethod method, IDictionary<string, object> htmlAttributes) {\r
129             TagBuilder tagBuilder = new TagBuilder("form");\r
130             tagBuilder.MergeAttributes(htmlAttributes);\r
131             // action is implicitly generated, so htmlAttributes take precedence.\r
132             tagBuilder.MergeAttribute("action", formAction);\r
133             // method is an explicit parameter, so it takes precedence over the htmlAttributes.\r
134             tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true);\r
135 \r
136             if (htmlHelper.ViewContext.ClientValidationEnabled) {\r
137                 // forms must have an ID for client validation\r
138                 tagBuilder.GenerateId(htmlHelper.ViewContext.FormIdGenerator());\r
139             }\r
140 \r
141             htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag));\r
142             MvcForm theForm = new MvcForm(htmlHelper.ViewContext);\r
143 \r
144             if (htmlHelper.ViewContext.ClientValidationEnabled) {\r
145                 htmlHelper.ViewContext.FormContext.FormId = tagBuilder.Attributes["id"];\r
146             }\r
147 \r
148             return theForm;\r
149         }\r
150 \r
151     }\r
152 }\r