Can you overload controller methods in ASP.NET MVC?

前端 未结 17 1875
无人共我
无人共我 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:51

    Here's something else you could do... you want a method that is able to have a parameter and not.

    Why not try this...

    public ActionResult Show( string username = null )
    {
       ...
    }
    

    This has worked for me... and in this one method, you can actually test to see if you have the incoming parameter.


    Updated to remove the invalid nullable syntax on string and use a default parameter value.

提交回复
热议问题