views:

53

answers:

1

Hi, I have an Ajax form :

<%using (Ajax.BeginForm(...)){%>
                    ...
   <input id="btn1" type="submit" value="OK1"/>
   <input id="btn2" type="submit" value="OK2"/>
<%} %>

both inputs do different jobs - is it possible to catch which input has been clicked ?

+1  A: 

Give your input buttons different names:

<input id="btn1" type="submit" name="action1" value="OK1"/>
<input id="btn2" type="submit" name="action2" value="OK2"/>

And then in the controller action check if action1 was clicked by looking at the request parameters (the name of the clicked button will be sent):

public ActionResult Index()
{
    if (!string.IsNullOrEmpty(Request["action1"]))
    {
        // action1 was clicked
    }
    // ...
    return View();
}
Darin Dimitrov