-
Notifications
You must be signed in to change notification settings - Fork 36
/
FormHelperHtmlHelpers.cs
33 lines (29 loc) · 1.71 KB
/
FormHelperHtmlHelpers.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.DependencyInjection;
namespace FormHelper
{
public static class FormHelperHtmlHelpers
{
public static HtmlString RenderFormScript(this IHtmlHelper html, FormConfig config)
{
var configuration = config.ViewContext.HttpContext.RequestServices.GetService<FormHelperOptions>();
return new HtmlString($@"
<script>
$(document).ready(function () {{
const $form = $('#{config.FormId}');
$form.attr('formhelper')
$form.attr('dataType', '{config.DataType}');
$form.attr('CheckTheFormFieldsMessage', '{configuration.CheckTheFormFieldsMessage}');
$form.attr('redirectDelay', '{configuration.RedirectDelay}');
$form.attr('beforeSubmit', '{config.BeforeSubmit}');
$form.attr('callback', '{config.Callback}');
$form.attr('enableButtonAfterSuccess', '{config.EnableButtonAfterSuccess}');
$form.attr('resetFormAfterSuccess', '{config.ResetFormAfterSuccess}');
$form.attr('toastrPositionClass', '{(config.ToastrPosition == null ? configuration.ToastrDefaultPosition.ToClassName() : config.ToastrPosition.Value.ToClassName())}');
}});
</script>
");
}
}
}