Can I have an ActionResult called “View”

寵の児 提交于 2019-12-21 04:38:09

问题


Code:

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

I currently get stackoverflow exceptions when I do this.


回答1:


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();



回答2:


Of course, just don't call yourself recursively:

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



回答3:


It's generally a good idea to name your views descriptively. A view named View doesn't say what the view does or the data it's likely to use. I would highly suggest giving it a better name.

That said, in this instance, you're recursively calling yourself, so change the return statement to

return base.View();


来源:https://stackoverflow.com/questions/5903633/can-i-have-an-actionresult-called-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!