2
Reply

Can we overload a action method in mvc ? If yes how it is and if not what is the reason ?

Ashvani chaudhary

Ashvani chaudhary

Dec 04, 2015
1.1k
0

    yes

    Manoj Kumar
    January 05, 2017
    0

    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

    Ashvani chaudhary
    December 04, 2015
    0