I\'ve tried to set up a small demo, in which an article has multiple comments. The article details view, should render the comments in a partial view. The partialView itself
To explain what is happening, you have a form that posts to you _CreateCommentForArticle()
method, which then renders your _GetCommentsForArticle.cshtml
partial which in turn includes @Html.Action("_CreateCommentForArticle", ...)
.
In the initial GET method for Details()
the view will be rendered correctly, but when you submit the form, the current request for the _GetCommentsForArticle
page is a [HttpPost]
method, so @Html.Action()
will look for a [HttpPost]
method (not the [HttpGet]
method). That [HttpPost]
in turn renders the _GetCommentsForArticle.cshtml
partial and again calls the _CreateCommentForArticle()
POST method which renders the _GetCommentsForArticle.cshtml
partial and so on until you run out of memory and the exception is thrown.
You can solve this by changing the name of the POST method, for example
[HttpPost]
public PartialViewResult Create(Comment comment, int articleId)
and modify the form to suit
@using (Ajax.BeginForm("Create", "Comments", new AjaxOptions { ...