1

I was trying to overload controller method or action I am able to write controller action and compile but still I am not getting result.

   public ActionResult Contact()
    {
        ViewBag.Message = "Your contact page.";

        return View();
    }
    public ActionResult Contact(string str)
    {
        ViewBag.Message = "Your contact page by overloaded method";

        return View();
    }

but still I am getting following Error Server Error in '/' Application

enter image description here

Vijaykumar
  • 127
  • 1
  • 10
  • 1
    Because both are the [HttpGet] for the same action, you can overload with the same name only if the HTTP verbs are different, otherwise use a different name. The Action Name attribute will also be helpful as suggested by thangadurai – Vinay Pratap Singh Bhadauria Sep 10 '15 at 12:25
  • 1
    No you can't. But you can simulate it using ActionName attribute. – Thangadurai Sep 10 '15 at 12:28

1 Answers1

4

You get the conflict because because string is nullable.

You can use [ActionName("NewActionName")] to give a different action name by leaving the method name intact.

You shouldn't get conflict if you have another action method like this

public ActionResult Contact(int Value)

But, below action will again fail

public ActionResult Contact(int? Value)

The reason is obvious. The parameter is again nullable.

Sateesh Pagolu
  • 9,282
  • 2
  • 30
  • 48