0
美好的一天,如何在不重新加載整個頁面的情況下刷新部分視圖中的kendo ui網格?
我有一個艱難的時間刷新剛剛放置在局部視圖內的劍道網格。看看代碼我目前使用我的部分觀點:
@model IEnumerable<TelerikMvcAscernAdmin2.Models.ConnectionViewModel>
@(Html.Kendo().Grid(Model).Name("id").Sortable().Columns(c => {
c.Bound(p => p.SystemId);
c.Bound(p => p.Host);
c.Bound(p => p.Port);})
.DataSource(datasoure =>datasoure.Server().PageSize(25).Sort(sort=>{sort.Add(c => c.Host).Ascending(); })
).Filterable()
.Pageable(p => p.PageSizes(new int[] { 25, 35, 40 })
.Refresh(true)).Groupable().Sortable().Scrollable(s => s.Height("200px")).RowAction(row => {
if (row.DataItem.Port == 0) row.HtmlAttributes["style"] = "background:red"; }).HtmlAttributes(new { style = "width: 800px;" }))
<script> $(document).ready(function() {
var refId = setInterval(function() {
var grid = $("#id").data("kendoGrid");
grid.dataSource.read();
}, 40000);
}); </script>
正如你所看到的,我使用的是服務器端的功能,這樣我就可以自動刷新該網格。我試着將它切換到Ajax函數,但是當我這樣做時,我的網格無法刷新。
我使我的主頁查看這裏面局部視圖,如下圖所示:
@Html.Action("EngineConnection", "GatewayConnections")
而且,看看我的動作控制器的方法,我在我的所有數據恢復到局部視圖:
public ActionResult EngineConnection()
{
var gatewayConnections = GatewayConnections.GetAllConnections();
var agents = Agent.RetrieveAgents();
var connectionViewModels = (from agent in agents.Where(a => a.Active)
join gatewayConnection in gatewayConnections on agent.SystemId equals gatewayConnection.ClientId into
agentConnections
from agentConnection in agentConnections.DefaultIfEmpty()
select
new ConnectionViewModel
{
SystemId = agent.SystemId,
Host = (agentConnection == null ? string.Empty : agentConnection.Host),
Port = (agentConnection == null ? 0 : agentConnection.Port)
}).ToList();
return PartialView("_EngineConnection", connectionViewModels);
}
我已經試過返回一個JSON對象,但似乎沒有辦法。有沒有辦法刷新網格,而不是整個頁面,並仍然保持在部分視圖內的網格?
任何建議都會有幫助!
謝謝
感謝您的輸入,我嘗試按照您的建議綁定網格。在頁面加載時,所有的數據都出現在網格中,但是當我刷新網格時,我的所有信息都會從網格中消失。我想知道它是否與行動方法有關。 –
經過進一步審查Ganesh提供的方法似乎是最好的選擇,我只需要創建一個不同的方法,將呈現JSON格式的信息,並在我的閱讀操作中指出它。 –