public MvcForm BeginForm(Action <BeginFormSetting> action, object attributes = null) { var setting = new BeginFormSetting(); action(setting); var attr = AnonymousHelper.ToDictionary(attributes); if (!attr.ContainsKey("class")) { attr.Set("class", "form-horizontal"); } attr.Set("action", this.htmlHelper.ViewContext.HttpContext.Request.RawUrl); if (setting.IsUploadForm) { attr.Set("enctype", "multipart/form-data"); } var meta = this.htmlHelper .When(JqueryBind.Submit) .DoWithPreventDefaultAndStopPropagation() .Submit() .OnBegin(dsl => dsl.Self().JqueryPlugIn().Block.Lock(options => { })) .OnError(dsl => dsl.Self().Core().Form.Validation.Refresh()) .OnSuccess(dsl => { if (setting.CloseDialog) { dsl.With(selector => selector.Id(GlobalSelector.DefaultDialogId)).JqueryUI().Dialog.Close(); } if (setting.ReloadSubmit) { dsl.With(selector => selector.Id(GlobalSelector.DefaultDialogId)).Core().Insert.Html(); dsl.With(selector => selector.Id(GlobalSelector.DefaultDialogId)).Browsio().CenterDialog(); } if (!string.IsNullOrWhiteSpace(setting.NotificationMessage)) { dsl.Self().JqueryPlugIn().Notification.PinesNoty.Show(options => { options.Text = setting.NotificationMessage; }); } if (setting.RedirectToSelf) { dsl.Utilities.Document.RedirectToSelf(); } if (setting.IsBack) { dsl.Utilities.Document.HistoryGo(-1); } }) .OnComplete(dsl => dsl.Self().JqueryPlugIn().Block.UnLock()) .AsHtmlAttributes(attr); return(this.htmlHelper.BeginForm(setting.Action, setting.Controller, FormMethod.Post, meta)); }
public BeginTag BeginForm <T>(Action <BeginFormSetting> configure) { var setting = new BeginFormSetting(); configure(setting); var url = new UrlHelper(HttpContext.Current.Request.RequestContext); return(this.helper.When(JqueryBind.Submit) .DoWithPreventDefault() .Submit(options => { options.Url = url.Dispatcher() .Push <T>(setting.Routes); }) .OnSuccess(dsl => { dsl.WithId(setting.TargetId).Core().Trigger.Incoding(); dsl.Self().Core().Form.Reset(); }) .AsHtmlAttributes() .ToBeginTag(this.helper, HtmlTag.Form)); }