简体   繁体   English

Ext.NET:如何在加载程序中呈现局部视图

[英]Ext.NET: How to render a partial view in a loader

I'm trying to load a partial view when a row is expanded in my grid. 我正在尝试在网格中扩展行时加载部分视图。 My listener looks like this: 我的听众看起来像这样:

x.RowExpander()
    .Listeners(ls =>
    {
        ls.Expand.Handler = string.Format("Item.onListRowExpand('{0}', {1}, this);",
            Url.Action("ItemDetail", "My"), Model);
    })

This calls into a JavaScript function: 这将调用JavaScript函数:

onListRowExpand: function(url, listId, expander) {
    var container = App.DashboardPanel;
    var itemId = expander.componentsCache[0].cmp.record.data.Id;
    var panelId = "Details_" + listId + "_" + itemId;

    // Check if the selected panel was selected again. If it was do nothing
    var panel = container.getComponent(panelId);
    if (!panel) {

        // Remove the opened panel so we can add a new one
        if (container.items.getCount() > 1) {
            container.remove(container.items.getAt(1).id);
        }

        // Add the new panel...
        container.add({
            id: panelId,
            closeable: true,
            loader: {
                xtype: "panel",
                url: url,
                renderer: "frame",
                params: {
                    "listId": listId,
                    "itemId": itemId                   }
            }
        });

        container.update();
    }
}

This method then calls into a controller: 然后,此方法调用控制器:

public Ext.Net.MVC.PartialViewResult ItemDetail(int listId, int itemId)
{
    var result = new Ext.Net.MVC.PartialViewResult
    {
        RenderMode = RenderMode.AddTo,
        ContainerId = "MyPanel",
        WrapByScriptTag = false,
        Model = new ItemViewModel
        {
            ListId = listId,
            ItemId = itemId
        }
    };

    return result;
}

which is supposed to return a partial view to be added onto the container's Items : 它应该返回要添加到容器的Items的局部视图:

@(x.Container()
    .ID("MyPanel")
    .Layout(LayoutType.HBox)
    .Loader(x.ComponentLoader()
        .Url(Url.Action("ViewList", "My"))
        .Mode(LoadMode.Script)
        .Params(new { listId = Model.ListId })))

The view looks like this: 该视图如下所示:

@model ItemViewModel
@{
    var x = Html.X();
}

@(x.Panel()
   .LayoutConfig(new HBoxLayoutConfig {Align = HBoxAlign.StretchMax})
    .Flex(1)
    .Items(
        x.Button().Text("Temp").Flex(1)))

My issue is that I cannot seem to get the partial view to render. 我的问题是我似乎无法获取部分视图。 It comes back as either a white box if I set WrapByScriptTag to true - in which case I get an error stating "Uncaught ReferenceError: Ext is not defined") or I get the component's JavaScript as text if I set WrapByScriptTag to false. 如果我将WrapByScriptTag设置为true,则返回为白框-在这种情况下,我将显示一条错误消息,指出“ Uncaught ReferenceError:未定义Ext”;或者,如果将WrapByScriptTag设置为false,则将获得组件的JavaScript作为文本。 I know I'm missing a setting somewhere but I'm not sure what's wrong. 我知道我在某处缺少设置,但不确定是否出问题。 Any help would be appreciated. 任何帮助,将不胜感激。

The solution for me was to change my controller to use RenderMode.Config and to change the renderer option on the loader from "frame" to "component" . 对我来说,解决方案是将控制器更改为使用RenderMode.Config并将加载renderer上的renderer选项从"frame"更改为"component" The difference, as I understand it, is that the frame option tells Ext.JS to expect an IFrame (ie fully-formed HTML) whereas the component option is used to described Ext components. 据我了解,区别在于frame选项告诉Ext.JS期望使用IFrame(即完全形成的HTML),而component选项用于描述Ext组件。 That was half the problem. 那是问题的一半。 The other half was that I was trying to render the component so it would be added into another container's Items field but the request originated from a call to add so this was unnecessary. 另一半是我试图渲染该组件,以便将其添加到另一个容器的Items字段中,但是该请求源自调用add的请求,因此这是不必要的。 Rather, rendering the component as a config made more sense because it was a partial view. 相反,将组件呈现为配置更有意义,因为它是局部视图。

Note that this works in Ext.NET 4.2.0 but not Ext.NET 4.1.0. 请注意,这在Ext.NET 4.2.0中有效,但在Ext.NET 4.1.0中无效。 In that case choosing renderer: "script" fixed the problem. 在这种情况下,选择renderer: "script"解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM