Orchard - Ajax只显示部分视图

时间:2013-04-08 04:29:43

标签: asp.net-mvc asp.net-ajax orchardcms

我正在开发一个Orchard项目,我正在努力让我的ajax代码在那里工作。

以下是观点:

    @model Ignite.Events.ViewModels.EventListPartViewModel
@{
    Script.Require("jQuery");
    Script.Include("EventList.js").AtLocation(Orchard.UI.Resources.ResourceLocation.Foot);
    Script.Include("fullcalendar.js").AtLocation(Orchard.UI.Resources.ResourceLocation.Foot);
    Script.Include("EventCalendar.js").AtLocation(Orchard.UI.Resources.ResourceLocation.Foot);
    Script.Include("jquery.unobtrusive-ajax.js").AtLocation(Orchard.UI.Resources.ResourceLocation.Foot);
    Style.Include("fullcalendar.css").AtLocation(Orchard.UI.Resources.ResourceLocation.Foot);
}

@using (Ajax.BeginForm("GetEventListItems", "Events", new { area="Ignite.Events", month = 4, year = 2013 }, new AjaxOptions { UpdateTargetId = "event-list", HttpMethod = "GET", InsertionMode = InsertionMode.Replace}, new { id = "ajaxForm" }))
{
    @Html.AntiForgeryToken();
    <input type="submit" value="Get Next" />
}
<table id="event-list" class="event-list">
    @Html.Partial("_EventList", Model.Events)
</table>

<div id="calendar" class="clear"></div>

这是一个返回局部视图的控制器:

[ValidateAntiForgeryToken]
        public PartialViewResult GetEventListItems(int? month, int? year)
        {
            if (month == null || year == null)
            {
                month = DateTime.Now.Month;
                year = DateTime.Now.Year;
            }

            var result = _eventListDataService.GetEventListItems((int) month, (int) year);

            return PartialView("_EventList", result);
        }

我想知道为什么我总是得到局部视图,而不是完整的视图,并在其中呈现局部视图。

谢谢,

的Jakub

1 个答案:

答案 0 :(得分:0)

仅呈现部分视图,因为这是GetEventListItems()返回的内容:PartialViewResult

将回报更改为ViewResult时会发生什么?

您还需要使用ThemedAttribute(true)装饰方法(或控制器)。