ASP.NET MVCで複数のボタンコミットを実現するための解決策


MVC開発では、1つのページに複数のコミットボタンがあり、異なるボタンは異なる機能に対応しています.例えば、監視解除監視
Webformでは議論しませんが、ASP.NET MVCの1つのフォームは1つのAction処理しか提出できません.比較的面倒ですが、次のように実現します.
実装方法:
まず、Webフロントエンド設定機能ボタンのname属性は次のようになります.
<input type="submit" value="  " name="actionForm" />
<input type="submit" value="    "  name="actionForm"/> 

そしてControllerで判断
//      
        [HttpPost]
        public ActionResult AdminUserProfile(string actionForm,string paramer1,string paramer2)
        {
            if (actionForm == "  ")
            {
                //    
                return RedirectToAction("TipInfo", "Common", new { area = "Office" });//       
            }
            else if (actionForm == "    ")
            {
                //    
                return RedirectToAction("TipInfo", "Common", new { area = "Office" });//       
            }
            else
            {
                //    
            }
            return View();
        }

Controllerのコードには、次のような書き方があります.
  //      
        [HttpPost]
        public ActionResult AdminUserProfile(FormCollection collection)
        {
            if (collection.Count > 0)
            {
                if (collection["actionForm"] == "  ")
                {
                    //    
                    return RedirectToAction("TipInfo", "Common", new { area = "Office" });//       
                }
                else if (collection["actionForm"] == "    ")
                {
                    //    
                    return RedirectToAction("TipInfo", "Common", new { area = "Office" });//       
                }
                else
                {
                    //    
                }
            }
            return View();
        }