Ashvani chaudhary
Can we overload a action method in mvc ? If yes how it is and if not what is the reason ?
By Ashvani chaudhary in Web Development on Dec 04 2015
  • Manoj Kumar
    Jan, 2017 5

    yes

    • 0
  • Ashvani chaudhary
    Dec, 2015 4

    we can overload a action method .it's work fine at the compile time but at run time browser show the error of ambiguity in action methodExample[HttpGet]public ActionResult Index (){return view();}[HttpGet]public ActionResult Index (int a) {return view();}// This code generated ambiguity of action method because HTTP doesnt understand Polymorphism it search the ControllerName/ActionName ....and here two mathod with same name exist so it reflect error to request a View . At the compile time it work well because C# support Polymorphism Solution : - [HttpGet]public ActionResult Index (){return view();}[HttpGet][ActionName("IndexNew")]public ActionResult Index (int a) {return view();}its work well but request would be ControllerName/IndexNew

    • 0