I have modified (one of my previous post) using
Entity framework 6, MVC Web Api, Ext Js 5.0, VS 2013. (With
create, read functions in database).
I can share the tutorial with you if requested.
Ext.define('Assingment.model.Color', { extend: 'Ext.data.Model', fields: [ { name: 'Id', type: 'int' }, { name: 'Value', type: 'int' }, { name: 'DomainId', type: 'int' }, { name: 'Colour', type: 'string' }, { name: 'Name', type: 'string' }, { name: 'ShortName', type: 'string' }, { name: 'Description', type: 'string' } ], schema: { namespace: 'Assingment.model', urlPrefix: '/Home/GetColorInformation', proxy: { type: 'ajax', url: '/Home/GetColorInformation', reader: { type: 'json', rootProperty: 'data' }, extraParams: { name: ' ' } } } });
4.2 view/main/Main.js is like this.
Ext.define('Assingment.view.main.Main', { extend: 'Ext.form.Panel', requires: ['Assingment.model.Color'], xtype: 'app-main', referenceHolder: true, controller: 'main', viewModel: { type: 'main' }, layout: { type: 'vbox', align: 'stretch' }, items: [ { xtype: 'form', bind: '{main}', items: [ { xtype: 'grid', bind: '{grid}', reference: 'fooPanel', columns: [ { text: "Colour", width: 120, dataIndex: 'Colour', renderer: function(value, metaData, record, rowIndex, colIndex, store) { metaData.style = 'background-color: #' + record.data.Colour; } }, { text: "Name", width: 380, dataIndex: 'Name' }, { text: "Short Name", width: 380, dataIndex: 'ShortName' }, { text: "Description", width: 380, dataIndex: 'Description' } ], buttons: [ { text: 'UpdateGrid', handler: 'onClickButton', } ], } ] }] });4.3. view/main/MainCOntroller.js is like this.Ext.define('Assingment.view.main.MainController', { extend: 'Ext.app.ViewController', requires: [ 'Ext.MessageBox' ], alias: 'controller.main', onClickButton: function () { var grid = this.lookupReference('fooPanel'); var store = grid.getStore(); store.load(); }, onConfirm: function (choice) { if (choice === 'yes') { // } } });4.4.view/main/MainModel.js where 'Color' is located in root Models/Color.csExt.define('Assingment.view.main.MainModel', { extend: 'Ext.app.ViewModel', requires: ['Assingment.model.Color'], alias: 'viewmodel.main', data: { name: 'Assingment' }, stores: { grid: { model: 'Color' } } });4.5 Color.cs contains follows.namespace Assignment2.Models { public class Color { public string Colour { get; set; } public string Name { get; set; } public string ShortName { get; set; } public string Description { get; set; } public int Id { get; set; } public int Value { get; set; } public int DomainId { get; set; } public Color() { } public Color(int id, string Name, int Value, string ShortName) { this.Id = id; this.Name = Name; this.Value = Value; this.ShortName = ShortName; } } }4.6. Root Controllers/HomeControllers.cs contains the action method like this.using System.Collections.Generic; using System.Web.Mvc; using Assignment2.Models; using Newtonsoft.Json; namespace Assignment2.Controllers { public class HomeController : Controller { public ActionResult Index() { return View(); } [HttpGet] [AllowAnonymous] public ActionResult GetColorInformation() { return this.JsonResponse( new { success = true, data = new List<Color> { new Color { Id = 1, Name = "Fixed", Value = 0, ShortName = "Fix", Description = "Issue is fixed and completed", Colour = "A4C400", DomainId = 0 }, new Color() { Id = 2, Name = "Can not reproduce", Value = 0, ShortName = "CantReprod", Description = "Reported issue can not be repoduced", Colour = "60A917", DomainId = 0 }, new Color() { Id = 3, Name = "Incomplete Data", Value = 0, ShortName = "Incomplete", Description = "Issue description is not enought", Colour = "FA6800", DomainId = 0 }, new Color() { Id = 4, Name = "Expected Behaviour", Value = 0, ShortName = "ExpctdBhvr", Description = "This is expected behaviour under the normal circumstances", Colour = "6D8764", DomainId = 0 }, } }); } protected ContentResult JsonResponse(object response) { return new ContentResult { Content = JsonConvert.SerializeObject(response), ContentType = "application/json", ContentEncoding = System.Text.Encoding.UTF8 }; } } }Following is my folder structure in VS.That's it. Now you can run in VS and see the grid content when pressing the button "UpdateGrid" in the browser.
@{ Layout = null; } <!DOCTYPE html> <html> <head> <title>ProjectManagement</title> <script id="microloader" type="text/javascript" src="bootstrap.js"></script> @* <script type="text/javascript" src="~/app.js"></script>*@ </head> <body class="body"> </body> </html>
ii. To enable jason MIME type, copy and paste the following change in your global Web.config file.
<staticContent> <mimeMap fileExtension=".json" mimeType="application/json" /> </staticContent>
Ext.define('Assingment.model.Contact', { extend: 'Ext.data.Model', alias: 'model', fields: [ { name: 'Name' }, { name: 'Company' }, 'Email', 'ContactPurpose', 'Subject', { name: 'Description' } ], schema: { namespace: 'MyApp.model', urlPrefix: '/Home/SubmitInformation', proxy: { api: { read: '{prefix}/{entityName:uncapitalize}', }, reader: { type: 'json', sucess: 'model.success' }, extraParams: { name: ' ' } } } });
4.2. view/main/Main.js is like this.
var namestore = new Ext.data.SimpleStore({ fields: ['contactPurpose'], data: [['General'],['Sales'],['Support']] }); Ext.define('Assingment.view.main.Main', { extend: 'Ext.form.Panel', xtype: 'app-main', controller: 'main', viewModel: { type: 'main' }, title: 'Contact Form', height: 1000, width: 1000, bodyPadding: 10, layout: 'form', items:[ { xtype: 'form', reference: 'fooForm', bind: '{main}', items: [ { fieldLabel: 'Name', name: 'name', xtype: 'textfield', bind: '{Name}' }, { fieldLabel: 'Company', name: 'company', xtype: 'textfield', bind: '{Company}' }, { fieldLabel: 'Email', name: 'email', vtype:'email', fieldStyle: 'background-color: #F7FE2E; background-image: none;', displayField: "email", xtype: 'textfield', bind: '{Email}' }, { xtype: 'combobox', fieldLabel: 'Contact Purpose', displayField: 'contactPurpose', name: "contactPurpose", store: namestore, bind: '{ContactPurpose}' }, { fieldLabel: 'Subject', name: 'subject', displayField: "subject", fieldStyle: 'background-color: #F7FE2E; background-image: none;', xtype: 'textfield', bind: '{Subject}', width: 450 }, { xtype: 'textareafield', grow: false, width: 450, bodyPadding: 10, name: 'description', fieldLabel: 'Description', autoScroll: true, bind: '{Description}' } ], buttons: [ { text: 'Submit', formBind: true, handler: 'onClickButton', }] }] });
Ext.define('Assingment.view.main.MainController', { extend: 'Ext.app.ViewController', requires: [ 'Assingment.model.Contact' ], alias: 'controller.main', onClickButton: function() { var form = this.lookupReference('fooForm'); if (form.isValid()) { url: form.submit({ url: '/Home/SubmitInformation', method: 'POST', success: function (form, action) { var data = Ext.JSON.decode(action.response.responseText); Ext.Msg.alert('Success', data.data); }, failure: function(form, action) { Ext.Msg.alert('Failed', action.result ? action.result.msg : 'No response'); }, params: { view: 'sencha', json: true } }); } }, onConfirm: function (choice) { if (choice === 'yes') { // } } });
4.4.view/main/MainModel.js where 'ContactInformation' is located in root Models/ContactInformation.cs
Ext.define('Assingment.view.main.MainModel', { extend: 'Ext.app.ViewModel', alias: 'viewmodel.main', data: { name: 'Assingment' }, stores: { model: 'ContactInformation' }, });4.5 ContactInformation.cs contains follows.
using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Assingment.Models { public class ContactInformation { public string Name { get; set; } public string Company { get; set; } public string ContactPurpose { get; set; } public string Description { get; set; } public string Subject { get; set; } public string Email { get; set; } public ContactInformation() {} public ContactInformation(string Name, string Company, string ContactPurpose,string Description, string Subject, string Email) { this.Name = Name; this.Company = Company; this.ContactPurpose = ContactPurpose; this.Description = Description; this.Subject = Subject; this.Email = Email; } } }4.6. Root Controllers/HomeControllers.cs contains the action method like this.using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using Assingment.Models; using Newtonsoft.Json; namespace Assingment.Controllers { public class HomeController : Controller { public ActionResult Index() { return View(); } [HttpPost] [AllowAnonymous] public ActionResult SubmitInformation(ContactInformation col) { return this.JsonResponse( new { success = true, data = "Your message have been received", }); } protected ContentResult JsonResponse(object response) { return new ContentResult { Content = JsonConvert.SerializeObject(response), ContentType = "application/json", ContentEncoding = System.Text.Encoding.UTF8 }; } } }Following is my folder structure in VS.That's it. Now you can run in VS and see the form in the browser.This is the output.Hope you this will help for you. :) You can try improve this example.