public static HtmlString RenderFormScript(this IHtmlHelper html, FormConfig config)
        {
            var configuration = config.ViewContext.HttpContext.RequestServices.GetService <FormHelperConfiguration>();

            return(new HtmlString($@"
                            <script>
                                $(document).ready(function () {{
                                    var $form = $('#{config.FormId}');
                                    $('#{config.FormId}').UseFormHelper({{
                                        url: $form.attr('action'),
                                        method: $form.attr('method'),
                                        dataType: '{config.DataType}',
                                        redirectDelay: {configuration.RedirectDelay},
                                        beforeSubmit: '{config.BeforeSubmit}',
                                        callback: '{config.Callback}',
                                        enableButtonAfterSuccess: {(config.EnableButtonAfterSuccess ? "true" : "false")},
                                        checkTheFormFieldsMessage: '{configuration.CheckTheFormFieldsMessage}'
                                    }});
                                }});
                            </script>
                            "));
        }
Exemple #2
0
        public static async Task <HtmlString> RenderFormScript(this IHtmlHelper html, FormConfig config)
        {
            var viewRenderHelper = config.ViewContext.HttpContext.RequestServices.GetService <IFormHelperViewRenderService>();
            var configuration    = config.ViewContext.HttpContext.RequestServices.GetService <FormHelperConfiguration>();

            var model = new RenderFormScriptModel
            {
                FormId         = config.FormId,
                Callback       = config.Callback,
                BeforeSubmit   = config.BeforeSubmit,
                IsMobileDevice = config.ViewContext.HttpContext.Request.IsMobileDevice()
            };

            var result = await viewRenderHelper.RenderToStringAsync("RenderFormScript", model);

            if (!configuration.DebugMode)
            {
                result = result.Replace("\r", "").Replace("\n", "").Replace("  ", "");
            }

            return(new HtmlString(result));
        }
Exemple #3
0
        public static async Task <HtmlString> RenderFormScript(this IHtmlHelper html, FormConfig config)
        {
            var viewRenderHelper = config.ViewContext.HttpContext.RequestServices.GetService <IFormHelperViewRenderService>();

            var model = new RenderFormScriptModel
            {
                FormId         = config.FormId,
                Callback       = config.Callback,
                IsMobileDevice = config.ViewContext.HttpContext.Request.IsMobileDevice()
            };

            var result = await viewRenderHelper.RenderToStringAsync("RenderFormScript", model);

            return(new HtmlString(result));
        }