如何区分asp mvc 4表单中的回发操作

Kye*_*Kye 1 asp.net-mvc

我有一个标准的ASP MVC 4表单,用户可以编辑一些细节,然后单击"批准"或"拒绝",这会导致回发.

当控制器在回发中收到模型时,我如何知道单击了哪个按钮?

我正在寻找一种标准的方法来做到这一点,所以我不会让下一个开发项目的开发人员神秘化.

编辑我正在使用立柱,

For*_*Two 6

为每个按钮指定一个名称(每个按钮都相同)和值(每个按钮唯一).

 <button type="submit" name="button" value="approve">Approve</button>
 <button type="submit" name="button" value="decline">Decline</button>
Run Code Online (Sandbox Code Playgroud)

然后在post方法中添加一个字符串参数,调用分配给按钮的名称.

 [HttpPost]
    public ActionResult ProcessForm (Model model, string button)
    {
        //the parameter 'button' will contain the value of the button clicked - either 'approve' or 'decline'
    }
Run Code Online (Sandbox Code Playgroud)