protected virtual string BeginForm <TModel>(IHtmlHelper htmlHelper, RoboUIFormResult <TModel> roboForm, string formId) where TModel : class { string formActionUrl = string.IsNullOrEmpty(roboForm.FormActionUrl) ? htmlHelper.ViewContext.HttpContext.Request.Path.ToString() : roboForm.FormActionUrl; var form = new FluentTagBuilder("form", TagRenderMode.StartTag) .MergeAttribute("action", formActionUrl) .MergeAttribute("id", formId) .MergeAttribute("method", roboForm.FormMethod.ToString().ToLowerInvariant()); if (roboForm.AjaxEnabled && roboForm.Layout == RoboFormLayout.Tab) { form = form.MergeAttribute("data-ajax-begin", formId.Replace("-", "_") + "_ValidateTabs"); } if (!roboForm.AjaxEnabled) { form = form.MergeAttribute("enctype", "multipart/form-data"); } else { form = form.MergeAttribute("data-ajax", "true"); } form = form.MergeAttribute("method", roboForm.FormMethod.ToString().ToLowerInvariant()); form = form.MergeAttributes(roboForm.HtmlAttributes); return(form.ToString()); }
public FluentTagBuilder(string tagName, TagRenderMode renderMode = TagRenderMode.Normal, FluentTagBuilder parent = null) { tagBuilder = new TagBuilder(tagName) { TagRenderMode = renderMode }; this.parent = parent; stringBuilder = new StringBuilder(); }
protected virtual string BeginForm <TModel>(IHtmlHelper htmlHelper, RoboUIGridResult <TModel> roboGrid) where TModel : class { if (string.IsNullOrEmpty(roboGrid.FormActionUrl)) { return(string.Empty); } var form = new FluentTagBuilder("form", TagRenderMode.StartTag) .MergeAttribute("action", roboGrid.FormActionUrl) .MergeAttribute("method", "post"); if (roboGrid.IsAjaxSupported) { form = form.MergeAttribute("data-ajax", "true"); } return(form.ToString()); }
protected virtual string BeginForm <TModel>(IHtmlHelper htmlHelper, RoboUIFormResult <TModel> roboForm, string formId) where TModel : class { var formActionUrl = string.IsNullOrEmpty(roboForm.FormActionUrl) ? htmlHelper.ViewContext.HttpContext.Request.Path.ToString() : roboForm.FormActionUrl; var form = new FluentTagBuilder("form", TagRenderMode.StartTag) .MergeAttribute("role", "form") .MergeAttribute("action", formActionUrl) .MergeAttribute("id", formId) .MergeAttribute("method", roboForm.FormMethod.ToString().ToLowerInvariant()); if (roboForm.IsHorizontal) { form.MergeAttribute("class", "form-horizontal"); } var formIdAsName = formId.Replace("-", "_"); if (roboForm.AjaxEnabled && roboForm.Layout == RoboFormLayout.Tab) { form.MergeAttribute("data-ajax-begin", formIdAsName + "_ValidateTabs"); } if (roboForm.AjaxEnabled) { form.MergeAttribute("data-ajax", "true"); form.MergeAttribute("data-ajax-failure", formIdAsName + "_OnFailure"); var scriptRegister = roboForm.ControllerContext.HttpContext.RequestServices.GetService <IScriptRegister>(); scriptRegister.AddInlineScript(string.Format("function {0}_OnFailure(xhr, status, error){{ var ct = xhr.getResponseHeader('content-type') || ''; if(ct.indexOf('application/x-javascript') == -1) {{ alert(xhr.responseText); }} }}", formIdAsName)); } else { form.MergeAttribute("enctype", "multipart/form-data"); } form.MergeAttribute("method", roboForm.FormMethod.ToString().ToLowerInvariant()); form.MergeAttributes(roboForm.HtmlAttributes); return(form.ToString()); }