Публикация формы Sitecore MVC

У меня есть 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}]


person AfshinZavvar    schedule 16.11.2016    source источник


Ответы (1)


Sitecore выдает эту ошибку, если детали макета или статическая привязка вызывают привязку подмакета или рендеринга к самому себе, что приводит к бесконечной рекурсии.

Я вижу в вашем коде - что ваше действие делает рекурсию к себе в конце.

IView pageView = Sitecore.Mvc.Presentation.PageContext.Current.PageView;
            if (pageView == null)
                return new HttpNotFoundResult();

            return (ActionResult) View(pageView);

Что вы можете сделать, это просто return View("index");

person Ahmad Harb    schedule 16.11.2016
comment
когда я возвращаю вид (индекс), Sitecore не может загрузить полный макет. он просто отображает текущую страницу с множеством тегов DIV. - person AfshinZavvar; 16.11.2016
comment
какую версию Sitecore вы используете? - person Ahmad Harb; 16.11.2016
comment
Замените @Html.Sitecore().FormHandler(NewsContent,Index) на этот @Html.Sitecore().FormHandler() . - person Ahmad Harb; 16.11.2016
comment
что, если вы добавите предложение and else: if (pageView == null) { return new HttpNotFoundResult(); } еще { return (ActionResult)this.View(pageView); } - person Santiago Morla; 17.11.2016