c#mvc4 Ext.Net.MVC.StoreResult不返回有效结果

时间:2012-10-10 10:45:01

标签: c# .net asp.net-mvc-4 ext.net gridpanel

我在MVC4 + EXT.NET库项目中创建StoreResult控制器,以响应GridPanel()中的JsonReader()。我的控制器返回字符串Ext.Net.MVC.StoreResult而不是json数据。我在VS2012,IIS8,MVC4中创建项目。

感谢您的帮助。

// IN VIEW

@(Html.X().GridPanel()
.ID("GridPanel1")
.Title("Array Grid")
.Width(600)
.Height(350)
.Store(s => s.Add(Html.X().Store()
    .PageSize(100)
    .Buffered(true)
    .AutoLoad(false)
    .Proxy(proxy=>proxy.Add(Html.X().AjaxProxy()
        .Url("/Data/GetData")
        .Reader(reader=>reader.Add(Html.X().JsonReader()
            .Root("data")))
     ))
    .Model(model => model.Add(Html.X().Model()
    .Fields(field =>
    {
        field.Add(Html.X().ModelField().Name("UserId"));
        field.Add(Html.X().ModelField().Name("UserName"));


    })
    ))

))
.VerticalScroller(scroller => scroller.Add(Html.X().GridPagingScroller()))
    .ColumnModel(columnModel =>
    {
        columnModel.Columns.Add(Html.X().Column()
            .Text("UserId")
            .DataIndex("UserID")
            .Flex(1)
            .Width(70));
        columnModel.Columns.Add(Html.X().Column()
            .Text("UserName")
            .DataIndex("UserName")
            .Flex(1));
        columnModel.Columns.Add(Html.X().Column()
            .Text("UserPassword")
            .DataIndex("UserPassword")
            .Flex(1));        
    })
.View(view => view.Add(Html.X().GridView().TrackOver(false)))
.Listeners(listeners =>
{
    listeners.AfterRender.Handler = "this.store.guaranteeRange(0,99);";
    listeners.AfterRender.Delay = 100;
})
)

///////// IN CONTROLLER

    public class DataController : System.Web.Mvc.Controller
    {
        //
        // GET: /Data/GetData/
        public Ext.Net.MVC.StoreResult GetData(int page = 1, int start = 0, int limit = 100)
        {

            StoreResult responce = new StoreResult();


            List<UserList> UserList = new List<UserList>();

            for (int i = start + 1; i <= start + limit; i++)
            {
                UserList user = new UserList()
                    {
                        UserId = i,
                        UserName = "UserName " + i
                    };
                UserList.Add(user);
            }

            responce.Data = UserList;
            responce.Total = 50000;
            return responce;


        }


    }

1 个答案:

答案 0 :(得分:1)

尝试更改此

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.5.7" />
    <assemblyIdentity name="Ext.Net.Utilities" publicKeyToken="2c34ac34702a3c23" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0" newVersion="2.0.1" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

到这个

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.5.7" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="Ext.Net.Utilities" publicKeyToken="2c34ac34702a3c23" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0" newVersion="2.0.1" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
  </dependentAssembly>
</assemblyBinding>
在您的web.config文件中