【发布时间】:2018-11-23 17:18:26
【问题描述】:
我正在尝试使用 Umbraco 实现 ajax 分页。
在服务器端,我有以下内容:
[System.Web.Http.HttpGet]
public JsonResult pagination(int? page)
{
IEnumerable<IPublishedContent> newsPosts = Umbraco.AssignedContentItem.DescendantOrSelf("news").Children.Where(x => x.IsVisible() && x.DocumentTypeAlias == "newsPost").OrderByDescending(x => x.UpdateDate).Take(5);
//from here on we will be returning the json within which information required for displaying post entries in carousel is included.
string json = "[some random string]"; //just random string for now.
return Json(json, JsonRequestBehavior.AllowGet);
}
如您所见,我正在尝试从 IPublishedContents 中获取必要的数据,但在实例化这一系列 IPublishedContents 时遇到问题。
这是我访问时遇到的错误:
locahost:{port}/umbraco/surface/{controller}/pagination 在 Chrome 上。
Cannot return the IPublishedContent because the UmbracoHelper was constructed with an UmbracoContext and the current request is not a front-end request.
Details: System.InvalidOperationException: Cannot return the IPublishedContent because the UmbracoHelper was constructed with an UmbracoContext and the current request is not a front-end request.
正如我所说,我从 Chrome 发出这个请求,我认为这意味着这个请求来自前端,所以我不确定我为什么会收到这个错误。
在搜索过程中我找到了这些
1) our.umbraco.com forum 2)stackoverflow post
- 无人问津,没有答案,至于 2,我觉得答案与我的情况不太相关。我想首先实例化 IPublishedContent。
我的是 Umbraco 7。
能否告诉我为什么前端的请求是不可取的?
任何提示将不胜感激。
谢谢,
【问题讨论】:
-
如果您发现我的回答是“我需要做的就是创建一个...的新实例”,请忘记它,我以为我做到了,但意识到这是因为我刚刚注释掉了关键线
-
您的控制器是否继承自 Surface?
标签: ajax pagination umbraco