0

我还尝试了以下代码..尝试使用处理程序

在索引.aspx

<ext:Store ID="Store1" IsPagingStore="true" runat="server">

             <Proxy>
                        <ext:AjaxProxy Url="../../Shared/JsonHandler.ashx">
                            <ActionMethods Read="GET" />
                            <Reader>

                                <ext:JsonReader Root="names" />
                            </Reader>
                        </ext:AjaxProxy>
                    </Proxy>
           <Model>
            <ext:Model ID="Model1" runat="server">
            <Fields>
            <ext:ModelField Name="name" Type="String" Mapping="nameList"  />

            </Fields>
            </ext:Model>
             </Model>
            </ext:Store>
            </Store>

在 JsonHandler.ashx 中

 public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType ="text/json";
        var requestParams = new StoreRequestParameters(context);

        FormExampleController ex=new FormExampleController ();

        var list = ex.getValue();

        context.Response.Write(string.Format("{{'Names':{0}}}",JSON.Serialize(list)));


    }

在表单控制器中

public List<string> getValue()
    {
        FormUser user = new FormUser();
        user.nameList = new List<string>
        {
            "A",
            "B",
            "C",
            "D"

        };
        return user.nameList;
    }

这里再次将值传递给处理程序,但组合框显示为空!有什么建议吗?

4

2 回答 2

0

是的,Store 不支持这种简单的结构。Store 需要对象的集合(对象应包含在模型中定义为字段的属性)

您应该将您的字符串列表转换为对象列表,例如

(new List<string>{"a", "b", "s"}).Select(s => new {FieldName = s})
于 2013-04-25T12:34:24.707 回答
0

似乎无法将其绑定Store到一个简单的ListArray字符串。

以下是一个应该有效但无效的测试用例。我正在研究解决方案,并将很快发布更新。

例子

<%@ Page Language="C#" %> 

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        var store = this.ComboBox1.GetStore();

        store.DataSource = new List<string> { "A", "B", "C", "D" };
        store.DataBind();
    }
</script>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
    <ext:ResourceManager runat="server" />

    <ext:ComboBox ID="ComboBox1" runat="server" DisplayField="name">
        <Store>
            <ext:Store runat="server">
                <Model>
                    <ext:Model runat="server">
                        <Fields>
                            <ext:ModelField Name="name" />
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        </Store>
    </ext:ComboBox>
</form>
</body>
</html>

以下示例绑定到一个简单List<object>的 .

例子

<%@ Page Language="C#" %> 

<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        var store = this.ComboBox1.GetStore();

        store.DataSource = new List<object> { 
            new { name = "A" }, 
            new { name = "B" }, 
            new { name = "C" }, 
            new { name = "D" } 
        };

        store.DataBind();
    }
</script>

<!DOCTYPE html>

<html>
<head runat="server">
    <title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
    <ext:ResourceManager runat="server" />

    <ext:ComboBox ID="ComboBox1" runat="server" DisplayField="name">
        <Store>
            <ext:Store runat="server">
                <Model>
                    <ext:Model runat="server">
                        <Fields>
                            <ext:ModelField Name="name" />
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        </Store>
    </ext:ComboBox>
</form>
</body>
</html>
于 2013-04-23T06:48:01.213 回答