I’m using ASP.Net MVC and implementing unobtrusive javascript for form validation. Here’s my code:
@{
AjaxOptions options = new AjaxOptions
{
HttpMethod = "Post",
LoadingElementId = "ProcessingMessageContainer",
Url = @Model.SaveUrl,
OnBegin = "OnBegin",
OnSuccess = "OnSaveSuccess",
OnFailure = "OnSaveFailure",
OnComplete = "OnComplete",
};
}
<div id="DataEntryFormContainer">
@using (Ajax.BeginForm(options))
{
[form here]
}
</div>
The problem is when I press the submit button the form is reloaded before the actual submission is processed on the server. So, it’s a bad user experience. The form data is delivered to the server and is processed accordingly. How do you keep the data entry form from being reloaded after user presses the submit button? Thanks.
I figured it out. I somehow bound 2 different actions to submit button. It was submitting the form and requesting the original page. I caught it by watching the console using firebug. Every time I submitted the form, i saw 2 requests to the server: 1 post for submitting the form and 1 get for retrieving the form. Thanks for everyone’s help.