.NetMVC与EXT4使用json进行前后台交互

:js部分

1.先定义model

 

Ext.define('ICeData', {
        extend: 'Ext.data.Model',
        fields: ['Author', 'Title', 'Manufacturer', 'ProductGroup']
    });

2.创建store

   

var store = new Ext.data.ArrayStore({
        model: 'ICeData',
        proxy: {
            type: 'ajax',
            url: appPath + 'Getjson', //url对应.NET控制器的动作
            reader: {
                type: 'json'
            }
        },
        fields: [//这里要和model的fields对应
           { name: 'Author' },
           { name: 'Title', type: 'float' },
           { name: 'Manufacturer', type: 'float' },
           { name: 'ProductGroup', type: 'float' }
        ]
});

 

3.为grid控件的 store属性赋值:

store: store


 

4.调用storeload方法

store.load();

:C#部分

1,建立一个简单:

public class Database
    {   //属性名字要和js的fields名字对应
	public string Author { get; set; }
        public double Title { get; set; }
        public double Manufacturer { get; set; }
        public double ProductGroup { get; set; }
 
        public Database(string Author, double Title, double Manufacturer, double ProductGroup)
        {
            this.Author = Author;
            this.Title = Title;
            this.Manufacturer = Manufacturer;
            this.ProductGroup = ProductGroup;
        }
 
    }



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章