Purpose of ActionName

后端 未结 6 1594
渐次进展
渐次进展 2020-11-27 03:37

What\'s the benefit of setting an alias for an action method using the \"ActionName\" attribute? I really don\'t see much benefit of it, in providing the user the option to

6条回答
  •  感情败类
    2020-11-27 03:56

    It is also helpful when you need to implement method overloading.

     public ActionResult ActorView()
            { 
    
                return View(actorsList);
            }
    
    
            [ActionName("ActorViewOverload")]
            public ActionResult ActorView(int id)
            {              
                return RedirectToAction("ActorView","Home");
            }
    `
    

    Here one ActorView accepts no parameters and the other accepts int. The first method used for viewing actor list and the other one is used for showing the same actor list after deleting an item with ID as 'id'. You can use action name as 'ActorViewOverload' whereever you need method overloading.

提交回复
热议问题