Alexander Beletsky's development blog

My profession is engineering

ASP.NET MVC controller's action with name View()

If you want to have action with name View in your controller, you will meet a small problem. Base class of any controller Controller already contains a method, with same name (and it is overloaded):

protected internal ViewResult View();
protected internal ViewResult View(IView view);
protected internal ViewResult View(object model);
protected internal ViewResult View(string viewName);

So, you code like this:

public ActionResult View(string url)
{
    // some action logic...

    return View();
}

Won’t complied, because you are adding method with same signature (name and parameters list). You have 2 options here: gave up to compiler and rename action, to something new like ViewPost or insist and try to make it happen.

Fortunately C# have beautiful feature for doing this. It is new Modifier. It hides the member on base class and explicitly says, that now your method is substituting it. So, everything you need is basically this:

new public ActionResult View(string url)
{
    // some action logic...

    return View();
}

It will make application compliable and work as expected.