// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; namespace Microsoft.AspNetCore.Mvc.Rendering { /// /// Form-related extensions for . /// public static class HtmlHelperFormExtensions { /// /// Renders a <form> start tag to the response. The <form>'s action attribute value will /// match the current request. /// /// The instance this method extends. /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm(this IHtmlHelper htmlHelper) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } // Generates
. return htmlHelper.BeginForm( actionName: null, controllerName: null, routeValues: null, method: FormMethod.Post, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. The <form>'s action attribute value will /// match the current request. /// /// The instance this method extends. /// /// If true, <form> elements will include an antiforgery token. /// If false, suppresses the generation an <input> of type "hidden" with an antiforgery token. /// If null, <form> elements will include an antiforgery token. /// /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm(this IHtmlHelper htmlHelper, bool? antiforgery) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } // Generates . return htmlHelper.BeginForm( actionName: null, controllerName: null, routeValues: null, method: FormMethod.Post, antiforgery: antiforgery, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. When the user submits the form, the /// current action will process the request. /// /// The instance this method extends. /// The HTTP method for processing the form, either GET or POST. /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm(this IHtmlHelper htmlHelper, FormMethod method) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginForm( actionName: null, controllerName: null, routeValues: null, method: method, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. When the user submits the form, the /// current action will process the request. /// /// The instance this method extends. /// The HTTP method for processing the form, either GET or POST. /// /// An that contains the HTML attributes for the element. Alternatively, an /// instance containing the HTML /// attributes. /// /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( this IHtmlHelper htmlHelper, FormMethod method, object htmlAttributes) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginForm( actionName: null, controllerName: null, routeValues: null, method: method, antiforgery: null, htmlAttributes: htmlAttributes); } /// /// Renders a <form> start tag to the response. When the user submits the form, the /// current action will process the request. /// /// The instance this method extends. /// The HTTP method for processing the form, either GET or POST. /// /// If true, <form> elements will include an antiforgery token. /// If false, suppresses the generation an <input> of type "hidden" with an antiforgery token. /// If null, <form> elements will include an antiforgery token only if /// is not . /// /// /// An that contains the HTML attributes for the element. Alternatively, an /// instance containing the HTML /// attributes. /// /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( this IHtmlHelper htmlHelper, FormMethod method, bool? antiforgery, object htmlAttributes) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginForm( actionName: null, controllerName: null, routeValues: null, method: method, antiforgery: antiforgery, htmlAttributes: htmlAttributes); } /// /// Renders a <form> start tag to the response. When the user submits the form, the /// current action will process the request. /// /// The instance this method extends. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm(this IHtmlHelper htmlHelper, object routeValues) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginForm( actionName: null, controllerName: null, routeValues: routeValues, method: FormMethod.Post, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. When the user submits the form, the action with name /// will process the request. /// /// The instance this method extends. /// The name of the action method. /// The name of the controller. /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( this IHtmlHelper htmlHelper, string actionName, string controllerName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginForm( actionName, controllerName, routeValues: null, method: FormMethod.Post, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. When the user submits the form, the action with name /// will process the request. /// /// The instance this method extends. /// The name of the action method. /// The name of the controller. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( this IHtmlHelper htmlHelper, string actionName, string controllerName, object routeValues) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginForm( actionName, controllerName, routeValues, FormMethod.Post, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. When the user submits the form, the action with name /// will process the request. /// /// The instance this method extends. /// The name of the action method. /// The name of the controller. /// The HTTP method for processing the form, either GET or POST. /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( this IHtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginForm( actionName, controllerName, routeValues: null, method: method, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. When the user submits the form, the action with name /// will process the request. /// /// The instance this method extends. /// The name of the action method. /// The name of the controller. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// The HTTP method for processing the form, either GET or POST. /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( this IHtmlHelper htmlHelper, string actionName, string controllerName, object routeValues, FormMethod method) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginForm( actionName, controllerName, routeValues, method, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. When the user submits the form, the action with name /// will process the request. /// /// The instance this method extends. /// The name of the action method. /// The name of the controller. /// The HTTP method for processing the form, either GET or POST. /// /// An that contains the HTML attributes for the element. Alternatively, an /// instance containing the HTML /// attributes. /// /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginForm( this IHtmlHelper htmlHelper, string actionName, string controllerName, FormMethod method, object htmlAttributes) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginForm( actionName, controllerName, routeValues: null, method: method, antiforgery: null, htmlAttributes: htmlAttributes); } /// /// Renders a <form> start tag to the response. The first route that can provide a URL with the /// specified generates the <form>'s action attribute value. /// /// The instance this method extends. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm(this IHtmlHelper htmlHelper, object routeValues) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginRouteForm( routeName: null, routeValues: routeValues, method: FormMethod.Post, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. The first route that can provide a URL with the /// specified generates the <form>'s action attribute value. /// /// The instance this method extends. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// /// If true, <form> elements will include an antiforgery token. /// If false, suppresses the generation an <input> of type "hidden" with an antiforgery token. /// If null, <form> elements will include an antiforgery token. /// /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm(this IHtmlHelper htmlHelper, object routeValues, bool? antiforgery) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginRouteForm( routeName: null, routeValues: routeValues, method: FormMethod.Post, antiforgery: antiforgery, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. The route with name /// generates the <form>'s action attribute value. /// /// The instance this method extends. /// The name of the route. /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm(this IHtmlHelper htmlHelper, string routeName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginRouteForm( routeName, routeValues: null, method: FormMethod.Post, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. The route with name /// generates the <form>'s action attribute value. /// /// The instance this method extends. /// The name of the route. /// /// If true, <form> elements will include an antiforgery token. /// If false, suppresses the generation an <input> of type "hidden" with an antiforgery token. /// If null, <form> elements will include an antiforgery token. /// /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm(this IHtmlHelper htmlHelper, string routeName, bool? antiforgery) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginRouteForm( routeName, routeValues: null, method: FormMethod.Post, antiforgery: antiforgery, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. The route with name /// generates the <form>'s action attribute value. /// /// The instance this method extends. /// The name of the route. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm( this IHtmlHelper htmlHelper, string routeName, object routeValues) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginRouteForm( routeName, routeValues, FormMethod.Post, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. The route with name /// generates the <form>'s action attribute value. /// /// The instance this method extends. /// The name of the route. /// The HTTP method for processing the form, either GET or POST. /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm( this IHtmlHelper htmlHelper, string routeName, FormMethod method) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginRouteForm( routeName, routeValues: null, method: method, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. The route with name /// generates the <form>'s action attribute value. /// /// The instance this method extends. /// The name of the route. /// /// An that contains the parameters for a route. The parameters are retrieved through /// reflection by examining the properties of the . This is typically /// created using initializer syntax. Alternatively, an /// instance containing the route /// parameters. /// /// The HTTP method for processing the form, either GET or POST. /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm( this IHtmlHelper htmlHelper, string routeName, object routeValues, FormMethod method) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginRouteForm( routeName, routeValues, method, antiforgery: null, htmlAttributes: null); } /// /// Renders a <form> start tag to the response. The route with name /// generates the <form>'s action attribute value. /// /// The instance this method extends. /// The name of the route. /// The HTTP method for processing the form, either GET or POST. /// /// An that contains the HTML attributes for the element. Alternatively, an /// instance containing the HTML /// attributes. /// /// /// An instance which renders the </form> end tag when disposed. /// /// /// In this context, "renders" means the method writes its output using . /// public static MvcForm BeginRouteForm( this IHtmlHelper htmlHelper, string routeName, FormMethod method, object htmlAttributes) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.BeginRouteForm( routeName, routeValues: null, method: method, antiforgery: null, htmlAttributes: htmlAttributes); } } }