How to overload controller in Asp.Net MVC?

Total Post:128

 1482  View(s)
Rate this:
Im 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 arguements. Is this something that cannot be done?
  1. Post:194

    Re: How to overload controller in Asp.Net MVC?

    Yes. I've been able to do this by setting the HttpGet/HttpPost (or equivalent AcceptVerbs attribute) for each controller method to something distinct, i.e., HttpGet or HttpPost, but not both. That way it can tell based on the type of request which method to use.

            public ActionResult Show()
            public ActionResult Show(string userName)

    One suggestion I have is that, for a case like this, would be to have a private implementation that both of your public Action methods rely on to avoid duplicating code.

      Modified On Apr-05-2018 07:03:26 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.