/// <summary>
 /// Generates the Form preamble
 /// </summary>
 /// <param name="html"></param>
 /// <param name="controllerName"></param>
 /// <param name="routeValues"></param>
 /// <param name="htmlAttributes"></param>
 /// <param name="actionType"></param>
 /// <returns></returns>
 public static MvcForm BeginResourceForm(this HtmlHelper html, string controllerName, object routeValues, object htmlAttributes, ActionType actionType) {
     switch (actionType) {
         case ActionType.GetUpdateForm:
             return html.BeginRouteForm(controllerName + "-editForm", routeValues, FormMethod.Post, htmlAttributes);
         case ActionType.GetCreateForm:
             return html.BeginRouteForm(controllerName + "-createForm", FormMethod.Post, htmlAttributes);
         case ActionType.Retrieve:
         case ActionType.Delete:
         case ActionType.Update:
             return html.BeginRouteForm(controllerName, routeValues, FormMethod.Post, htmlAttributes);
         case ActionType.Create:
             return html.BeginRouteForm(controllerName + "-create", FormMethod.Post, htmlAttributes);
         case ActionType.Index:
             return html.BeginRouteForm(controllerName + "-index", FormMethod.Post, htmlAttributes);
         default:
             throw new ArgumentOutOfRangeException("actionType");
     }
 }
 /// <summary>
 /// Generates the Form preamble
 /// </summary>
 /// <param name="ajax"></param>
 /// <param name="controllerName"></param>
 /// <param name="routeValues"></param>
 /// <param name="ajaxOptions"></param>
 /// <param name="actionType"></param>
 /// <returns></returns>
 public static MvcForm BeginResourceForm(this AjaxHelper ajax, string controllerName, object routeValues, AjaxOptions ajaxOptions, ActionType actionType) {
     switch (actionType) {
         case ActionType.GetUpdateForm:
             return ajax.BeginRouteForm(controllerName + "-editForm", routeValues, ajaxOptions);
         case ActionType.GetCreateForm:
             return ajax.BeginRouteForm(controllerName + "-createForm", ajaxOptions);
         case ActionType.Retrieve:
         case ActionType.Delete:
         case ActionType.Update:
             // can we use ajaxOptions to either add the header?
             MvcForm form = ajax.BeginRouteForm(controllerName, routeValues, ajaxOptions);
             return form;
         case ActionType.Create:
             return ajax.BeginRouteForm(controllerName + "-create", ajaxOptions);
         case ActionType.Index:
             return ajax.BeginRouteForm(controllerName + "-index", ajaxOptions);
         default:
             throw new ArgumentOutOfRangeException("actionType");
     }
 }
 public static MvcForm BeginERPStoreRouteForm(this HtmlHelper htmlHelper, string routeName, object routeValues, FormMethod method)
 {
     routeName = htmlHelper.ResolveRouteName(routeName);
     return htmlHelper.BeginRouteForm(routeName, routeValues, method);
 }
Example #4
0
 public static MvcForm BeginRouteTokenForm(this HtmlHelper htmlHelper, string routeName)
 {
     var mvcForm = htmlHelper.BeginRouteForm(routeName);
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }
 public static MvcForm BeginERPStoreRouteForm(this HtmlHelper htmlHelper, string routeName, FormMethod method, object htmlAttributes)
 {
     routeName = htmlHelper.ResolveRouteName(routeName);
     return htmlHelper.BeginRouteForm(routeName, method, htmlAttributes);
 }
        /// <summary>
        /// Renders a &lt;form&gt; start tag to the response. The route with name <paramref name="routeName"/>
        /// generates the &lt;form&gt;'s <c>action</c> attribute value.
        /// </summary>
        /// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
        /// <param name="routeName">The name of the route.</param>
        /// <param name="method">The HTTP method for processing the form, either GET or POST.</param>
        /// <param name="htmlAttributes">
        /// An <see cref="object"/> that contains the HTML attributes for the element. Alternatively, an
        /// <see cref="System.Collections.Generic.IDictionary{string, object}"/> instance containing the HTML
        /// attributes.
        /// </param>
        /// <returns>
        /// An <see cref="MvcForm"/> instance which renders the &lt;/form&gt; end tag when disposed.
        /// </returns>
        /// <remarks>
        /// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
        /// </remarks>
        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,
                htmlAttributes: htmlAttributes);
        }
Example #7
0
 public static MvcForm BeginRouteTokenForm(this HtmlHelper htmlHelper, string routeName, RouteValueDictionary routeValues, FormMethod method, IDictionary<string, object> htmlAttributes)
 {
     var mvcForm = htmlHelper.BeginRouteForm(routeName, routeValues, method, htmlAttributes);
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }
Example #8
0
 /// <summary>
 /// Writes an opening &lt;form&gt; tag to the response. When the user submits the form, the request will be processed by the route target.
 /// </summary>
 /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
 /// <param name="routeName">The name of the route to use to obtain the form-post URL.</param>
 /// <param name="attributeExpression">An expression that contains the HTML attributes to set for the element.</param>
 /// <returns>An opening &lt;form&gt; tag.</returns>
 public static MvcForm BeginRouteForm( this HtmlHelper htmlHelper, string routeName, Action<HtmlAttributeBuilder> attributeExpression )
 {
     return htmlHelper.BeginRouteForm( routeName, null, FormMethod.Post, attributeExpression.GetAttributes() );
 }
Example #9
0
 /// <summary>
 /// Writes an opening &lt;form&gt; tag to the response. When the user submits the form, the request will be processed by the route target.
 /// </summary>
 /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
 /// <param name="routeName">The name of the route to use to obtain the form-post URL.</param>
 /// <param name="routeValues">An object that contains the parameters for a route.</param>
 /// <param name="method">The HTTP method for processing the form, either GET or POST.</param>
 /// <param name="attributeExpression">An expression that contains the HTML attributes to set for the element.</param>
 /// <returns>An opening &lt;form&gt; tag.</returns>
 public static MvcForm BeginRouteForm( this HtmlHelper htmlHelper, string routeName, RouteValueDictionary routeValues, FormMethod method, Action<HtmlAttributeBuilder> attributeExpression )
 {
     return htmlHelper.BeginRouteForm( routeName, routeValues, method, attributeExpression.GetAttributes() );
 }
Example #10
0
 public static MvcForm BeginRouteForm(this AjaxHelper ajaxHelper, string routeName, Task<ActionResult> taskResult, AjaxOptions ajaxOptions)
 {
     return ajaxHelper.BeginRouteForm(routeName, taskResult.Result, ajaxOptions, null);
 }
Example #11
0
 public static MvcForm BeginRouteForm(this AjaxHelper ajaxHelper, string routeName, Task<ActionResult> taskResult, AjaxOptions ajaxOptions, object htmlAttributes)
 {
     return ajaxHelper.BeginRouteForm(routeName, taskResult.Result, ajaxOptions, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
 }
Example #12
0
 public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, Task<ActionResult> taskResult, FormMethod method, object htmlAttributes)
 {
     return htmlHelper.BeginRouteForm(routeName, taskResult.Result, method, HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes));
 }
Example #13
0
 public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, Task<ActionResult> taskResult, FormMethod method, IDictionary<string, object> htmlAttributes)
 {
     return htmlHelper.BeginRouteForm(routeName, taskResult.Result, method, htmlAttributes);
 }
Example #14
0
 public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, Task<ActionResult> taskResult, FormMethod method)
 {
     return htmlHelper.BeginRouteForm(routeName, taskResult.Result, method, null);
 }
Example #15
0
 public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, Task<ActionResult> taskResult)
 {
     return htmlHelper.BeginRouteForm(null, taskResult.Result, FormMethod.Post, null);
 }
Example #16
0
 public static MvcForm BeginRouteForm(this HtmlHelper htmlHelper, string routeName, ActionResult result)
 {
     return htmlHelper.BeginRouteForm(routeName, result, FormMethod.Post, null);
 }
Example #17
0
 public static MvcForm BeginERPStoreRouteForm(this AjaxHelper helper, string routeName, AjaxOptions options)
 {
     routeName = helper.ResolveRouteName(routeName);
     return helper.BeginRouteForm(routeName, options);
 }
Example #18
0
 public static MvcForm BeginRouteForm(this AjaxHelper ajaxHelper, string routeName, Task<ActionResult> taskResult, AjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes)
 {
     return ajaxHelper.BeginRouteForm(routeName, taskResult.Result, ajaxOptions, htmlAttributes);
 }
Example #19
0
 /// <summary>
 /// Writes an opening &lt;form&gt; tag to the response. When the user submits the form, the request will be processed by the route target.
 /// </summary>
 /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
 /// <param name="routeValues">An object that contains the parameters for a route.</param>
 /// <param name="attributeExpression">An expression that contains the HTML attributes to set for the element.</param>
 /// <returns>An opening &lt;form&gt; tag.</returns>
 public static MvcForm BeginRouteForm( this HtmlHelper htmlHelper, RouteValueDictionary routeValues, Action<HtmlAttributeBuilder> attributeExpression )
 {
     return htmlHelper.BeginRouteForm( null, routeValues, FormMethod.Post, attributeExpression.GetAttributes() );
 }
Example #20
0
 public static IDisposable FormRoute(this HtmlHelper html, string routeName, FormMethod method, RouteValueDictionary valuesDictionary)
 {
     VirtualPathData virtualPath = RouteTable.Routes.GetVirtualPath(html.ViewContext.RequestContext, routeName, valuesDictionary);
     string formAction = (virtualPath == null) ? null : virtualPath.VirtualPath;
     return html.BeginRouteForm(routeName, method, valuesDictionary);
 }
Example #21
0
 /// <summary>
 /// Writes an opening &lt;form&gt; tag to the response. When the user submits the form, the request will be processed by the route target.
 /// </summary>
 /// <param name="htmlHelper">The HTML helper instance that this method extends.</param>
 /// <param name="routeName">The name of the route to use to obtain the form-post URL.</param>
 /// <param name="routeValues">
 ///		An object that contains the parameters for a route. The parameters are retrieved through reflection by examining the properties of the object.
 ///		The object is typically created by using object initializer syntax.
 /// </param>
 /// <param name="attributeExpression">An expression that contains the HTML attributes to set for the element.</param>
 /// <returns>An opening &lt;form&gt; tag.</returns>
 public static MvcForm BeginRouteForm( this HtmlHelper htmlHelper, string routeName, object routeValues, Action<HtmlAttributeBuilder> attributeExpression )
 {
     return htmlHelper.BeginRouteForm( routeName, new RouteValueDictionary( routeValues ), FormMethod.Post, attributeExpression.GetAttributes() );
 }
 public static MvcForm BeginLocalizedRouteForm(this HtmlHelper htmlHelper, string routeName, object routeValues,  FormMethod method)
 {
     var currentLanguage = GetCurrentLanguage(htmlHelper);
     routeName = string.Format("{0}-{1}", routeName, currentLanguage);
     return htmlHelper.BeginRouteForm(routeName, routeValues, method);
 }
        /// <summary>
        /// Renders a &lt;form&gt; start tag to the response. The first route that can provide a URL with the
        /// specified <paramref name="routeValues"/> generates the &lt;form&gt;'s <c>action</c> attribute value.
        /// </summary>
        /// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
        /// <param name="routeValues">
        /// An <see cref="object"/> that contains the parameters for a route. The parameters are retrieved through
        /// reflection by examining the properties of the <see cref="object"/>. This <see cref="object"/> is typically
        /// created using <see cref="object"/> initializer syntax. Alternatively, an
        /// <see cref="System.Collections.Generic.IDictionary{string, object}"/> instance containing the route
        /// parameters.
        /// </param>
        /// <returns>
        /// An <see cref="MvcForm"/> instance which renders the &lt;/form&gt; end tag when disposed.
        /// </returns>
        /// <remarks>
        /// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
        /// </remarks>
        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,
                htmlAttributes: null);
        }
Example #24
0
 public static MvcForm SecureBeginRouteForm(this HtmlHelper htmlHelper, string routeName, ActionResult result, FormMethod method, IDictionary<string, object> htmlAttributes)
 {
     return htmlHelper.BeginRouteForm(routeName, result.GetRouteValueDictionary(), method, htmlAttributes);
 }
        /// <summary>
        /// Renders a &lt;form&gt; start tag to the response. The route with name <paramref name="routeName"/>
        /// generates the &lt;form&gt;'s <c>action</c> attribute value.
        /// </summary>
        /// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
        /// <param name="routeName">The name of the route.</param>
        /// <param name="suppressAntiforgery">
        /// If <c>true</c>, suppresses the generation an &lt;input&gt; of type "hidden" with an antiforgery token. By
        /// default &lt;form&gt; elements will automatically include an antiforgery token.
        /// </param>
        /// <returns>
        /// An <see cref="MvcForm"/> instance which renders the &lt;/form&gt; end tag when disposed.
        /// </returns>
        /// <remarks>
        /// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
        /// </remarks>
        public static MvcForm BeginRouteForm(this IHtmlHelper htmlHelper, string routeName, bool suppressAntiforgery)
        {
            if (htmlHelper == null)
            {
                throw new ArgumentNullException(nameof(htmlHelper));
            }

            return htmlHelper.BeginRouteForm(
                routeName,
                routeValues: null,
                method: FormMethod.Post,
                suppressAntiforgery: suppressAntiforgery,
                htmlAttributes: null);
        }
Example #26
0
 public static MvcForm BeginRouteTokenForm(this HtmlHelper htmlHelper, string routeName, object routeValues, FormMethod method)
 {
     var mvcForm = htmlHelper.BeginRouteForm(routeName, routeValues, method);
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }
 public static MvcForm BeginLocalizedRouteForm(this AjaxHelper helper, string routeName, AjaxOptions options)
 {
     var currentLanguage = GetCurrentLanguage(helper);
     routeName = string.Format("{0}-{1}", routeName, currentLanguage);
     return helper.BeginRouteForm(routeName, options);
 }
        /// <summary>
        /// Renders a &lt;form&gt; start tag to the response. The route with name <paramref name="routeName"/>
        /// generates the &lt;form&gt;'s <c>action</c> attribute value.
        /// </summary>
        /// <param name="htmlHelper">The <see cref="IHtmlHelper"/> instance this method extends.</param>
        /// <param name="routeName">The name of the route.</param>
        /// <param name="routeValues">
        /// An <see cref="object"/> that contains the parameters for a route. The parameters are retrieved through
        /// reflection by examining the properties of the <see cref="object"/>. This <see cref="object"/> is typically
        /// created using <see cref="object"/> initializer syntax. Alternatively, an
        /// <see cref="System.Collections.Generic.IDictionary{string, object}"/> instance containing the route
        /// parameters.
        /// </param>
        /// <param name="method">The HTTP method for processing the form, either GET or POST.</param>
        /// <returns>
        /// An <see cref="MvcForm"/> instance which renders the &lt;/form&gt; end tag when disposed.
        /// </returns>
        /// <remarks>
        /// In this context, "renders" means the method writes its output using <see cref="ViewContext.Writer"/>.
        /// </remarks>
        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,
                suppressAntiforgery: false,
                htmlAttributes: null);
        }
Example #29
0
 public static MvcForm SecureBeginRouteForm(this AjaxHelper ajaxHelper, string routeName, ActionResult result, AjaxOptions ajaxOptions, IDictionary<string, object> htmlAttributes)
 {
     return ajaxHelper.BeginRouteForm(routeName, result.GetRouteValueDictionary(), ajaxOptions, htmlAttributes);
 }
Example #30
0
 public static MvcForm BeginRouteTokenForm(this HtmlHelper htmlHelper, RouteValueDictionary routeValues)
 {
     var mvcForm = htmlHelper.BeginRouteForm(routeValues);
     htmlHelper.ViewContext.Writer.Write(htmlHelper.AntiForgeryToken().ToHtmlString());
     return mvcForm;
 }