Html.BeginForm没有onBegin,onComplete方法,如Ajax.BeginForm

时间:2017-06-28 12:50:31

标签: javascript jquery ajax asp.net-mvc

我在ASP.NET MVC 5中工作。 我在使用Ajax.BeginForm:

的表单提交期间显示一个加载器
Application: devenv.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException
   at Microsoft.VisualStudio.Shell.Connected.Common.CommonUtilities.ResetUserTokenStorage(Microsoft.VisualStudio.Services.Client.AccountManagement.IAccountManager)
   at Microsoft.VisualStudio.Shell.Connected.UserInformation.UserInformationDataSource.SignoutAndClearKeychain()
   at Microsoft.VisualStudio.Shell.Connected.UserInformation.UserInformationDataSource.UserInformationCommandHandler(Microsoft.VisualStudio.Shell.Interop.IVsUIDispatch, System.String, System.Object, System.Object ByRef)
   at Microsoft.Internal.VisualStudio.PlatformUI.UIDispatch.Invoke(System.String, System.Object, System.Object ByRef)
   at Microsoft.VisualStudio.Shell.Connected.UserInformation.UserInformationDataSource.PrepareForFirstLaunchSignIn()
   at Microsoft.VisualStudio.Shell.Connected.UserInformation.UserInformationDataSource.UserInformationCommandHandler(Microsoft.VisualStudio.Shell.Interop.IVsUIDispatch, System.String, System.Object, System.Object ByRef)
   at Microsoft.Internal.VisualStudio.PlatformUI.UIDispatch.Invoke(System.String, System.Object, System.Object ByRef)
   at Microsoft.Internal.VisualStudio.PlatformUI.DataSource.Invoke(System.String, System.Object, System.Object ByRef)
   at Microsoft.VisualStudio.Shell.Connected.UserInformation.FirstLaunchSignIn.FirstLaunchSignIn_Loaded(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.RoutedEventHandlerInfo.InvokeHandler(System.Object, System.Windows.RoutedEventArgs)
   at System.Windows.EventRoute.InvokeHandlersImpl(System.Object, System.Windows.RoutedEventArgs, Boolean)
   at System.Windows.UIElement.RaiseEventImpl(System.Windows.DependencyObject, System.Windows.RoutedEventArgs)
   at System.Windows.UIElement.RaiseEvent(System.Windows.RoutedEventArgs)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(System.Windows.DependencyObject, System.Windows.RoutedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(System.Object)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(System.Object)
   at System.Windows.Media.MediaContext.RenderMessageHandler(System.Object)
   at System.Windows.Media.MediaContext.Resize(System.Windows.Media.ICompositionTarget)
   at System.Windows.Interop.HwndTarget.OnResize()
   at System.Windows.Interop.HwndTarget.HandleMessage(MS.Internal.Interop.WindowMessage, IntPtr, IntPtr)
   at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndWrapper.WndProc(IntPtr, Int32, IntPtr, IntPtr, Boolean ByRef)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(System.Object)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate, System.Object, Int32)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(System.Object, System.Delegate, System.Object, Int32, System.Delegate)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(System.Windows.Threading.DispatcherPriority, System.TimeSpan, System.Delegate, System.Object, Int32)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.HwndSubclass.DefWndProcWrapper(IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.UnsafeNativeMethods.CallWindowProc(IntPtr, IntPtr, Int32, IntPtr, IntPtr)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr, Int32, IntPtr, IntPtr)

我正在尝试在另一个我有Html.BeginForm的网页上做同样的事情:

@using (Ajax.BeginForm("Filter", "Log", new AjaxOptions() { OnSuccess = "reloadGrid", OnFailure = "notifyError", HttpMethod = "POST", LoadingElementId = "myModalLoader", OnBegin= "showLoader();", OnComplete = "hideLoader();" }, new { @id = "filter-form" }))

但onBegin和OnComplete不会触发。

你知道原因吗?我可以在Html.BeginForm中使用AjaxOptions吗?

由于

西蒙

1 个答案:

答案 0 :(得分:3)

不,你不能用Html.BeginForm做到这一点。

您不能将Html.BeginForm呈现为<form>标记,而当您按submit按钮时,会导致向服务器发出同步请求。

如果您确实想要根据请求执行某些操作,则可以在控制器内的服务器端执行此操作。重定向或只是替换页面视图。

无论如何,如果你想对网页的某些部分做些什么,你应该使用Ajax.BeginForm代替Html.BeginForm