Can I get an ActionResult called View,

The code:

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

I am currently getting stackoverflow exceptions when I do this.

+6
source share
3 answers

You should get a compiler warning that your View definition masks the base controller class and that you must explicitly use the new keyword. If you change your code to do this, it should work as you would like:

 return base.View(); 
+14
source

Of course, just don't call yourself recursively:

 public new ActionResult View() { return base.View(); } 
+6
source

As a rule, it’s nice to call your views descriptively. A view named View does not say it is making a view or data that it can use. I would really like to give him a better name.

In this case, you recursively call yourself, so change the return statement to

 return base.View(); 
+4
source

Source: https://habr.com/ru/post/887405/


All Articles