3
votes

I'm working in ASP.NET MVC 5. I'm showing a loader during a form submit using a Ajax.BeginForm:

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

I'm trying to do the same thing in another web page where I've a Html.BeginForm:

@using (Html.BeginForm( "Index", "GestioneImmagini", FormMethod.Get, new AjaxOptions() { HttpMethod = "GET",  LoadingElementId = "myModalLoader", OnBegin = "showLoader();", OnComplete = "hideLoader();" }))

But onBegin and OnComplete don't fire.

Do you know the reason? Can I use AjaxOptions in Html.BeginForm?

Thanks

Simone

1
No. Its not ajax! - user3559349
There is no such method of OnComplete for Html.BeginForm - Laxman Gite

1 Answers

3
votes

No you can't do it with Html.BeginForm.

The reason why you can not is that Html.BeginForm renders as <form> tag and when you pressing submit button this results in synchronous request to server.

If you actually want to do something on request complete you can do it on server side inside controller. Something like redirect or just replace page view.

Anyway if you want to do something with part of the page you should use Ajax.BeginForm instead of Html.BeginForm