Click here to Skip to main content
15,747,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have two buttons in my page and i want to invoke two different methods on each different button click.

@using (Html.BeginForm("DeleteConfirmed", "Thomson"))
    <div style="float:left;" class="panel123 col-sm-4">
            <div class="form-group">
                @Html.TextBoxFor(a => a.UName)
                @Html.ValidationMessageFor(a => a.UName)

            <div class="form-group">
                @Html.PasswordFor(a => a.Password)
                @Html.ValidationMessageFor(a => a.Password)
            <div align="center">
                <input type="submit" value="Submit" id="btnSubmit" class="btn-default" />
            <input type="submit" value="Delete" id="btnDelete" class="btn-default" />

But i am unable to invoke another method how can i do achieve this?
phil.o 15-Sep-15 7:02am    
Please define "unable to invoke another method".
Thanks7872 15-Sep-15 7:45am    
I dont see even a single click event and not clear what is the problem here.

1 solution

Give your input buttons the same name;

<input name="submit" .... />

then add a "name" attribute to your action

public Action DeleteConfirmed(YourModelType model, string submit)
  // the value of "submit" will be "Submit" or "Delete" depending on which button was pressed
Share this answer
chandra sekhar 15-Sep-15 7:37am    
I want to invoke different methods in controller.As of now one button is hitting DeleteConfirmed method as i have mentioned but what about another method?
F-ES Sitecore 15-Sep-15 7:40am    
You can't easily call different actions, you'll need to call the relevant functions inside your action.

public Action DeleteConfirmed(YourModelType model, string submit)
if (submit == "Submit")
else if (submit == "Delete")

chandra sekhar 15-Sep-15 7:43am    
Is there any other way of doing this?
F-ES Sitecore 15-Sep-15 7:45am    
Yes, but they're the wrong way to do it, this is the right way.

Edit: This is an ok solution too, probably the best non-js\non-html5 answer
[no name] 15-Sep-15 9:59am    
Sir I have post an article on Working with Hadoop Cluster Set up but you said it is copied and it was deleted.I have written that article my own.Please tell me from where I have copied..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900