У меня есть ControllerRedering и представление, которое показывает контент новостей и частичное представление под ним, что позволяет пользователю добавлять новый комментарий.
@using (Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, FormMethod.Post, new { @class = "form-inline", role = "form" }))
{
@Html.Sitecore().FormHandler("NewsContent","Index")
some controlls here...
<div class="form-group">
<input type="submit" value="Add" class="btn btn-default"/>
</div>
}
и это содержимое контроллера:
public class NewsContentController : Controller
{
//shows news content
public ActionResult Index()
{
var model = Factory.Context.GetCurrentItem<INews>();
return View(model);
}
//saves comment
[HttpPost]
public ActionResult Index(Comment comment)
{
//get current item
var parent = Factory.Context.GetCurrentItem<INews>();
IComment _comment = new Comment
{
Description = comment.Description,
FullName = comment.FullName,
Name = DateTime.Now.ToString("yy-MM-ddThh-mm-ss")
};
var db = Factory.GetSitecoreService(Factory.SiteCoreDataBase.master);
using (new SecurityDisabler())
{
db.Create(parent, _comment);
}
ViewBag.Message = "Thanks for comment";
IView pageView = Sitecore.Mvc.Presentation.PageContext.Current.PageView;
if (pageView == null)
return new HttpNotFoundResult();
return (ActionResult) View(pageView);
}
}
После того как я нажимаю на кнопку добавить, он говорит, что
Рендеринг был рекурсивно встроен в себя. Тропа встраивания: Content-Controller: NewsContent. Действие: Index [Контроллер контента: NewsContent. Действие: Index- {04234ec6-d54e-4eb7-81df-402493d29c4f}] --> Content-Controller: NewsContent. Действие: Index [Контроллер контента: NewsContent. Действие: индекс- {04234ec6-d54e-4eb7-81df-402493d29c4f}]