In Ajax.BeginForm, you can specify the following arguments

1. The name of the action method that will handle the request.

2. The name of the controller.

3. ajaxOptions : An object that provides options for the asynchronous request.

There are a many of overloads too, which you can read here

BeginForm Syntax

public static MvcForm BeginForm(  
    this AjaxHelper ajaxHelper,  
    string actionName,  
    string controllerName,  
    AjaxOptions ajaxOptions  
)

MVC 3 Razor Code

using (Ajax.BeginForm("ActionName", "ControllerName", new AjaxOptions {HttpMethod = "POST", UpdateTargetId = "myDivId" }))  
{  
// all other input elements + submit buttons can go in here  
}

Now under AjaxOption there are various methods like

1. OnBegin

2. OnComplete

3. OnSuccess

4. OnFailure

their detailed explanation and when to use these options is described here

In this article I shall be using the OnBegin Method, this OnBegin method is called just before the call to the action is made. So using this we can have a JavaScript validation done and depending on the output of that validation we can control whether the call to the action is to be made or not.

Now in the below code, you can see that I have added an OnBegin option under AjaxOptions of my BeginForm. There I have used “return Validate()” JS method.

MVC 3 Razor Code

using (Ajax.BeginForm("ActionName", "ControllerName", new AjaxOptions { OnBegin = "return Validate()", HttpMethod = "POST", UpdateTargetId = "myDivId" }))  
{  
    // all other input elements + submit buttons can go in here  
}

Javascript

function Validate() {

    if(someCondition){  
        return false;  
    }
    else {  
        return true;  
    }  
}  

You can also pass arguments to this JS function as

OnBegin = "return Validate('" + @variableName + "')"