Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I have an ActionResult called "View"

Code:

public ActionResult View(string id)
{ 
   return View();
}

I currently get stackoverflow exceptions when I do this.

like image 275
rick schott Avatar asked May 05 '11 20:05

rick schott


People also ask

Can I write ActionResult Instead of view result?

So if you are sure that your action method will return some view page, you can use ViewResult. But if your action method may have different behavior, like either render a view or perform a redirection. You can use the more general base class ActionResult as the return type.

What does ActionResult mean?

What is an ActionResult? An ActionResult is a return type of a controller method, also called an action method, and serves as the base class for *Result classes. Action methods return models to views, file streams, redirect to other controllers, or whatever is necessary for the task at hand.

How can we call a view in asp net?

Inside the Views folder, we will add another folder for views that are associated with our HomeController and call that folder Home. Right-click on the Home folder and select Add → New Item. In the left pane, select the MVC View Page and enter index. cshtml in the name field and click on the Add button.


2 Answers

You should be getting a compiler warning that your definition of View masks that of the base controller class and that you should explicitly use the new keyword. If you change your code to do this instead, it should work as you'd like:

return base.View();
like image 97
Jacob Avatar answered Sep 22 '22 17:09

Jacob


Of course, just don't call yourself recursively:

public new ActionResult View()
{
    return base.View();
}
like image 30
Darin Dimitrov Avatar answered Sep 24 '22 17:09

Darin Dimitrov