Sitecore MVC表单发布

Sitecore MVC表单发布,sitecore,sitecore-mvc,Sitecore,Sitecore Mvc,我有一个ControllerRedering和一个显示新闻内容的视图,下面有一个局部视图,允许用户添加新的评论 @using (Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName, FormMethod.Post, new { @class = "form-inline", role = "form" })) { @Html.Sitecore().FormHand

我有一个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>

    }
@使用(Html.BeginRouteForm(Sitecore.Mvc.Configuration.MvcSettings.SitecoreRouteName,FormMethod.Post,new{@class=“form inline”,role=“form”}))
{
@Html.Sitecore().FormHandler(“新闻内容”、“索引”)
这里有一些控制器。。。
}
这是控制器的内容:

   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);
        }
    }
公共类NewsContentController:控制器
{
//显示新闻内容
公共行动结果索引()
{
var model=Factory.Context.GetCurrentItem();
返回视图(模型);
}
//保存评论
[HttpPost]
公共行动结果索引(评论)
{
//获取当前项目
var parent=Factory.Context.GetCurrentItem();
IComment _comment=新注释
{
Description=comment.Description,
FullName=comment.FullName,
Name=DateTime.Now.ToString(“yy-MM-ddThh-MM-ss”)
};
var db=Factory.GetSitecoreService(Factory.SiteCoreDataBase.master);
使用(新的SecurityDisabler())
{
创建(父项,_注释);
}
ViewBag.Message=“感谢您的评论”;
IView pageView=Sitecore.Mvc.Presentation.PageContext.Current.pageView;
如果(页面视图==null)
返回新的HttpNotFoundResult();
返回(操作结果)视图(页面视图);
}
}
在我点击add按钮后,它显示

渲染已递归地嵌入到自身中。嵌入轨迹:内容控制器:新闻内容。操作:索引[内容控制器:新闻内容。操作:索引-{04234ec6-d54e-4eb7-81df-402493d29c4f}]-->内容控制器:新闻内容。操作:索引[内容控制器:新闻内容。操作:索引-{04234ec6-d54e-4eb7-81df-402493d29c4f}]


如果布局详细信息或静态绑定导致子布局或渲染绑定到自身,从而导致无限递归,则Sitecore会引发此错误

我可以从你的代码中看出,你的动作最终会自己递归

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

            return (ActionResult) View(pageView);

您可以做的只是
返回视图(“索引”)

如果布局详细信息或静态绑定导致子布局或呈现绑定到自身,从而导致无限递归,则Sitecore会引发此错误

我可以从你的代码中看出,你的动作最终会自己递归

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

            return (ActionResult) View(pageView);

您可以做的只是
返回视图(“索引”)

当我返回视图(“索引”)时,Sitecore无法加载完整的布局。它只是呈现当前页面,其中包含许多DIV标记,而您使用的是Sitecore的版本?将@Html.Sitecore().FormHandler(“新闻内容”、“索引”)替换为@Html.Sitecore().FormHandler()。如果您添加and else子句:if(pageView==null){return new HttpNotFoundResult();}否则{return(ActionResult)this.View(pageView);}当我返回视图(“索引”)时,Sitecore无法加载完整的布局。它只是呈现当前页面,其中包含许多DIV标记,而您使用的是Sitecore的版本?将@Html.Sitecore().FormHandler(“新闻内容”、“索引”)替换为@Html.Sitecore().FormHandler()。如果您添加and else子句:if(pageView==null){return new HttpNotFoundResult();}否则{return(ActionResult)this.View(pageView);}