/// <summary> /// This renders out the form for us /// </summary> /// <param name="htmlHelper"></param> /// <param name="formAction"></param> /// <param name="method"></param> /// <param name="htmlAttributes"></param> /// <param name="surfaceController"></param> /// <param name="surfaceAction"></param> /// <param name="area"></param> /// <param name="additionalRouteVals"></param> /// <returns></returns> /// <remarks> /// This code is pretty much the same as the underlying MVC code that writes out the form /// </remarks> private static MvcForm RenderForm(this IHtmlHelper htmlHelper, string formAction, FormMethod method, IDictionary<string, object> htmlAttributes, string surfaceController, string surfaceAction, string area, object additionalRouteVals = null) { if (htmlAttributes == null) { htmlAttributes = new Dictionary<string, object>(); } //ensure that the multipart/form-data is added to the html attributes if (htmlAttributes.ContainsKey("enctype") == false) { htmlAttributes.Add("enctype", "multipart/form-data"); } var tagBuilder = new TagBuilder("form"); tagBuilder.MergeAttributes(htmlAttributes); // action is implicitly generated, so htmlAttributes take precedence. tagBuilder.MergeAttribute("action", formAction); // method is an explicit parameter, so it takes precedence over the htmlAttributes. tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true); tagBuilder.TagRenderMode = TagRenderMode.StartTag; tagBuilder.WriteTo(htmlHelper.ViewContext.Writer, new HtmlEncoder()); //new UmbracoForm: var theForm = new UmbracoForm(htmlHelper.UrlEncoder, htmlHelper.ViewContext, surfaceController, surfaceAction, area, additionalRouteVals); return theForm; }
/// <summary> /// This renders out the form for us /// </summary> /// <param name="htmlHelper"></param> /// <param name="formAction"></param> /// <param name="method"></param> /// <param name="htmlAttributes"></param> /// <param name="surfaceController"></param> /// <param name="surfaceAction"></param> /// <param name="area"></param> /// <param name="additionalRouteVals"></param> /// <returns></returns> /// <remarks> /// This code is pretty much the same as the underlying MVC code that writes out the form /// </remarks> private static MvcForm RenderForm(this IHtmlHelper htmlHelper, string formAction, FormMethod method, IDictionary <string, object> htmlAttributes, string surfaceController, string surfaceAction, string area, object additionalRouteVals = null) { if (htmlAttributes == null) { htmlAttributes = new Dictionary <string, object>(); } //ensure that the multipart/form-data is added to the html attributes if (htmlAttributes.ContainsKey("enctype") == false) { htmlAttributes.Add("enctype", "multipart/form-data"); } var tagBuilder = new TagBuilder("form"); tagBuilder.MergeAttributes(htmlAttributes); // action is implicitly generated, so htmlAttributes take precedence. tagBuilder.MergeAttribute("action", formAction); // method is an explicit parameter, so it takes precedence over the htmlAttributes. tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true); tagBuilder.TagRenderMode = TagRenderMode.StartTag; tagBuilder.WriteTo(htmlHelper.ViewContext.Writer, new HtmlEncoder()); //new UmbracoForm: var theForm = new UmbracoForm(htmlHelper.UrlEncoder, htmlHelper.ViewContext, surfaceController, surfaceAction, area, additionalRouteVals); return(theForm); }
/// <summary> /// This renders out the form for us /// </summary> /// <param name="htmlHelper"></param> /// <param name="formAction"></param> /// <param name="method"></param> /// <param name="htmlAttributes"></param> /// <param name="surfaceController"></param> /// <param name="surfaceAction"></param> /// <param name="area"></param> /// <param name="surfaceId"></param> /// <param name="additionalRouteVals"></param> /// <returns></returns> /// <remarks> /// This code is pretty much the same as the underlying MVC code that writes out the form /// </remarks> private static MvcForm RenderForm(this HtmlHelper htmlHelper, string formAction, FormMethod method, IDictionary <string, object> htmlAttributes, string surfaceController, string surfaceAction, string area, Guid?surfaceId, object additionalRouteVals = null) { var tagBuilder = new TagBuilder("form"); tagBuilder.MergeAttributes(htmlAttributes); // action is implicitly generated, so htmlAttributes take precedence. tagBuilder.MergeAttribute("action", formAction); // method is an explicit parameter, so it takes precedence over the htmlAttributes. tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true); var traditionalJavascriptEnabled = htmlHelper.ViewContext.ClientValidationEnabled && !htmlHelper.ViewContext.UnobtrusiveJavaScriptEnabled; if (traditionalJavascriptEnabled) { // forms must have an ID for client validation tagBuilder.GenerateId("form" + Guid.NewGuid().ToString("N")); } htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag)); //new UmbracoForm: var theForm = new UmbracoForm(htmlHelper.ViewContext, surfaceController, surfaceAction, area, surfaceId, additionalRouteVals); if (traditionalJavascriptEnabled) { htmlHelper.ViewContext.FormContext.FormId = tagBuilder.Attributes["id"]; } return(theForm); }
/// <summary> /// This renders out the form for us /// </summary> /// <remarks> /// This code is pretty much the same as the underlying MVC code that writes out the form /// </remarks> private static MvcForm RenderForm( this IHtmlHelper htmlHelper, string formAction, FormMethod method, IDictionary <string, object?> htmlAttributes, string surfaceController, string surfaceAction, string area, object?additionalRouteVals = null) { // ensure that the multipart/form-data is added to the HTML attributes if (htmlAttributes.ContainsKey("enctype") == false) { htmlAttributes.Add("enctype", "multipart/form-data"); } var tagBuilder = new TagBuilder("form"); tagBuilder.MergeAttributes(htmlAttributes); // action is implicitly generated, so htmlAttributes take precedence. tagBuilder.MergeAttribute("action", formAction); // method is an explicit parameter, so it takes precedence over the htmlAttributes. tagBuilder.MergeAttribute("method", HtmlHelper.GetFormMethodString(method), true); var traditionalJavascriptEnabled = htmlHelper.ViewContext.ClientValidationEnabled; if (traditionalJavascriptEnabled) { // forms must have an ID for client validation tagBuilder.GenerateId("form" + Guid.NewGuid().ToString("N"), string.Empty); } htmlHelper.ViewContext.Writer.Write(tagBuilder.RenderStartTag()); HtmlEncoder htmlEncoder = GetRequiredService <HtmlEncoder>(htmlHelper); // new UmbracoForm: var theForm = new UmbracoForm(htmlHelper.ViewContext, htmlEncoder, surfaceController, surfaceAction, area, additionalRouteVals); if (traditionalJavascriptEnabled) { htmlHelper.ViewContext.FormContext.FormData["FormId"] = tagBuilder.Attributes["id"]; } return(theForm); }