Can you overload controller methods in ASP.NET MVC?

前端 未结 17 1665
无人共我
无人共我 2020-11-22 08:10

I\'m curious to see if you can overload controller methods in ASP.NET MVC. Whenever I try, I get the error below. The two methods accept different arguments. Is this some

17条回答
  •  终归单人心
    2020-11-22 08:46

    Create the base method as virtual

    public virtual ActionResult Index()
    

    Create the overridden method as override

    public override ActionResult Index()
    

    Edit: This obviously applies only if the override method is in a derived class which appears not to have been the OP's intention.

提交回复
热议问题