Monday 6 November 2017

How to overload action method in mvc?

Overloading means the same function name with different parameter or signature.

But, when we try to apply the same overloading in MVC then it will Show you the error like "Ambiguous" because the HTTP does not undestand Polymorphism.

To Resolve the error we need to Use "ActionName" attribute.

Example:-

public class TestController : Controller
{
public ActionResult LoadEmp()
{
return Content("Load all Employee.");
}

[ActionName(LoadEmpByName)]
public ActionResult LoadEmp(int Id)
{
return Content("Load Employee based on Id.")
}


}

0 comments:

Post a Comment