ASP .NET MVC NonAction meaning

后端 未结 10 1726
没有蜡笔的小新
没有蜡笔的小新 2021-01-03 17:39

Can anybody please tell me why should I use NonAction? I mean say I have a form with several submit values: Update, Delete or Insert. Since all the submit buttons have the s

10条回答
  •  情书的邮戳
    2021-01-03 18:14

    It is worth noting that the need to use [NonAction] applies only to public methods. Protected and private methods are not treated as actions. Since your Update/Delete/Insert methods are helpers for asd(), a private method would be more appropriate for your scenario:

    public ActionResult asd(string submitButton){
        switch(submitButton){
            case "Insert":
                return Insert();
            // bla bla bla
        }
    }
    
    ActionResult Insert(){
        // some code inside here
    }
    

提交回复
热议问题