How to best implement Save | Save and Close | Cancel form actions in ASP.NET MVC 3 RC

后端 未结 2 1517
别那么骄傲
别那么骄傲 2021-02-13 13:33

I\'m wondering how you might go about implementing multiple form actions when submitting a form in asp.net mvc 3 RC.

If I\'m editing a user, for example I would like to

2条回答
  •  醉酒成梦
    2021-02-13 14:11

    You can have multiple submit buttons in a form with the same name attribute but different value attributes. Which ever button is clicked, the associated value will be posted to the server.

    You can use a simple link for Cancel but I'll include it as a button anyway.

    
    
    
    

    And in your action, test for the values.

    public ActionResult Edit(string actionType)
    {
        if(actionType == "Save")
        {
            // Save action
        }
        else if (actionType == "Save and Close")
        {
            // Save and quit action
        }
        else
        {
            // Cancel action
        }
    }
    

    If you don't like having the long text in the value attribute, you can use standard HTML

提交回复
热议问题