Thursday, June 2, 2011

Confirm a request using multiple submit buttons.

   Recently i have faced a situation to confirm an Inactivate request from user.I have done it using multiple submit buttons.In ASP.net MVC we can bind the submit buttons value using same binding methods. Use two submit buttons in Confirm view.

<p>
    <input type="submit" name="Confirm" value="Confirm"/>
    <input type ="submit" name="Cancel" value="Cancel" />
</p>


We used name="confirm" and name="cancel" to bind the submit buttons values. if an user clicked on confirm button then  the ActionResult method string variable 'Confirm' will bind with a value "Confirm" and string Cancel will be null else vice versa. By checking this values we can perform the required action.
        [HttpPostActionName("InActive")]
        public ActionResult InActiveConfirmed(string Confirm, string Cancel)
        {
            var response = Confirm ?? Cancel;
 
            if (response == "Confirm")
            {
                // do the things..
                // In Activate the item
            }
            else
            {
                // return back with out InActivating Item
            }
 
 
        }

0 comments:

Post a Comment