---
title: "How to action overloading in MVC"  
description: "How to action overloading in MVC"  
author: "Anonymous User"  
published: 2015-10-27  
updated: 2015-10-27  
canonical: https://www.mindstick.com/forum/33539/how-to-action-overloading-in-mvc  
category: ".net"  
tags: ["mvc"]  
reading_time: 2 minutes  

---

# How to action overloading in MVC

Can [anyone](https://www.mindstick.com/articles/23207/how-to-find-the-best-fit-job-for-anyone) please help me how to [solve this problem](https://answers.mindstick.com/qa/94681/my-google-assistant-shows-completely-different-search-results-from-what-i-ask-how-can-i-solve-this-problem).

## Replies

### Reply by Anonymous User

```
Overloading or in other
words polymorphism is a feature of object oriented programming. So if you have
some kind of a below controller code which has methods overloaded with same
name and different argument's it would compile very well.
public class CustomerController : Controller
    {               // GET: /Customer/
    Public ActionResult GetCustomer()
        {
         return Content("GetCustomer");
        }

    Public ActionResult GetCustomer(string id)
        {
         return Content("GetCustomer with a string");
        }

    } 

But now if you are
thinking that when you call "http://localhost:3450/Customer/GetCustomer/"
it should invoke "GetCustomer" and when you call
"http://localhost:3450/Customer/GetCustomer/test" it should invoke
"GetCustomer(string str)" you are WRONG.
```

```

```

```
Polymorphism is a part
of C# programming while HTTP is a protocol. HTTP does not understand
polymorphism it works on the concept's or URL and URL can only have unique
name's. So HTTP does not implement polymorphism.

And i know if you answer with the above argument MVC interviewer would still
press that he wants to implement polymorphism , so how do we go about doing it.

If you wish to keep polymorphism and also want the HTTP request to work you can
decorate one of the methods with "ActionName" as shown in the below
code.

public class CustomerController : Controller
    {
              // GET: /Customer/
    Public ActionResult GetCustomer()
        {
         return Content("GetCustomer");
        }
       [ActionName("GetCustomerbyid")]
    Public ActionResult GetCustomer(string id)
        {
         return Content("GetCustomer with a string");
        }
    }

So now you can invoke with URL structure "Customer/GetCustomer" the
"GetCustomer" action and with URL structure "Customer/GetCustomerByName"
the "GetCustomer(string id)" will be invoked.
```


---

Original Source: https://www.mindstick.com/forum/33539/how-to-action-overloading-in-mvc

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
