我有一个带有函数 ShowEvents(EventCategory eventCategory)
的 Controller 。是否可以从客户端 JavaScript 调用此函数?我知道我可以使用 Sitecore.Services.Client (SCC) 从数据库中检索项目,但是否有可能实际访问方法?也许通过 Controller 渲染,如果可能的话?
这是我要调用的方法的示例:
public class EventListController : Controller
{
public ActionResult ShowEvents(EventCategory eventCategory)
{
var repository = new EventListRepository();
var eventPages = repository.GetEvents(eventCategory);
var eventListViewModel = repository.GetEventListViewModel(eventPages);
return View("/Some/Path/, eventListViewModel);
}
}
这是在 Sitecore 7.5 MVC 上
最佳答案
您可以使用格式从客户端发送到 Controller
/api/sitecore/{yourcontroller}/{action}
在您的情况下,这将是 /api/sitecore/eventlist/showevents
传递 eventCategory
作为数据。
关于javascript - 从 JavaScript (MVC) 调用 Sitecore Controller 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34603174/