• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當(dāng)前位置: 首頁 - 科技 - 知識百科 - 正文

    Coolite Cool Study 3 MVC + Coolite 的實現(xiàn)代碼

    來源:懂視網(wǎng) 責(zé)編:小采 時間:2020-11-27 22:44:20
    文檔

    Coolite Cool Study 3 MVC + Coolite 的實現(xiàn)代碼

    Coolite Cool Study 3 MVC + Coolite 的實現(xiàn)代碼: 因為默認的 MVC 的樣式文件里對于的 table 和 其他相關(guān)樣式(h1~h6) 與Coolite有沖突,會導(dǎo)致GridPanel走樣,大家記得先把那個table 和 h1~h6的樣式清除掉才看到GridPanel的帥臉面 … 項目文件分布: 關(guān)于Coolite在MVC中的配置文件跟一般
    推薦度:
    導(dǎo)讀Coolite Cool Study 3 MVC + Coolite 的實現(xiàn)代碼: 因為默認的 MVC 的樣式文件里對于的 table 和 其他相關(guān)樣式(h1~h6) 與Coolite有沖突,會導(dǎo)致GridPanel走樣,大家記得先把那個table 和 h1~h6的樣式清除掉才看到GridPanel的帥臉面 … 項目文件分布: 關(guān)于Coolite在MVC中的配置文件跟一般

    MVC-Coolite

    因為默認的 MVC 的樣式文件里對于的 table 和 其他相關(guān)樣式(h1~h6) 與Coolite有沖突,會導(dǎo)致GridPanel走樣,大家記得先把那個table 和  h1~h6的樣式清除掉才看到GridPanel的帥臉面 …

    項目文件分布:

    ProjectFiles

    關(guān)于Coolite在MVC中的配置文件跟一般webform是一樣的。 但在MVC的Global.asax中,需要在 RegisterRoutes 方法里加上這一句:

    routes.IgnoreRoute("{exclude}/{coolite}/coolite.axd");

    另外 ScriptManager 要注明 IDMode="Static“:

    <ext:ScriptManager ID="ScriptManager1" runat="server"  IDMode="Static"/>

    其中唯一與一般MVC不同的是,我們需要定義自己的ActionResult來返回Json結(jié)果給客戶端。因為Coolite 的JsonReader 要求的格式大致都是這樣:{data: [{…}], totalCount: …}

    關(guān)于JsonReader的一般用法:

    <ext:JsonReader ReaderID="CustomerID" Root="data" TotalProperty="totalCount"> 

    所以, 要繼承MVC ActionResult 的抽象方法 public override void ExecuteResult(ControllerContext context)  來返回給 JsonReader   合適口味的 JsonResult , 不然它就不認人了。

    以下代碼實現(xiàn)了對Json Response & Save Response 的簡單封裝。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Coolite.Ext.Web;
    
    namespace CooliteMVC.Helper
    { 
     public class AjaxStoreResult : ActionResult
     {
     public AjaxStoreResult() { }
    
     public AjaxStoreResult(object data)
     {
     this.Data = data;
     }
    
     public AjaxStoreResult(object data, int totalCount)
     : this(data)
     {
     this.TotalCount = totalCount;
     }
    
     public AjaxStoreResult(StoreResponseFormat responseFormat)
     {
     this.ResponseFormat = responseFormat;
     }
    
     private object data;
     public object Data
     {
     get { return this.data; }
     set { this.data = value; }
     }
    
     private int totalCount;
     public int TotalCount
     {
     get { return this.totalCount; }
     set { this.totalCount = value; }
     }
    
     private StoreResponseFormat responseFormat = StoreResponseFormat.Load;
     public StoreResponseFormat ResponseFormat
     {
     get { return this.responseFormat; }
     set { this.responseFormat = value; }
     }
    
     private SaveStoreResponse saveResponse;
     public SaveStoreResponse SaveResponse
     {
     get
     {
     if (this.saveResponse == null)
     {
     this.saveResponse = new SaveStoreResponse();
     }
     return this.saveResponse;
     }
     }
    
     public override void ExecuteResult(ControllerContext context)
     {
     switch (this.ResponseFormat)
     {
     case StoreResponseFormat.Load:
    
     string json = Coolite.Ext.Web.JSON.Serialize(Data);
     json = "{data:" + json + ", totalCount:" + 100 + "}";
     context.HttpContext.Response.Write(json);
     
     break;
     case StoreResponseFormat.Save:
     Response response = new Response(true);
     response.Success = this.SaveResponse.Success;
     response.Msg = this.SaveResponse.ErrorMessage;
     StoreResponseData saveResponse = new StoreResponseData();
     saveResponse.Confirmation = this.SaveResponse.ConfirmationList;
     response.Data = saveResponse.ToString();
    
     response.Write();
     break;
     default:
     throw new ArgumentOutOfRangeException();
     }
     }
     
     }
    
     public enum StoreResponseFormat
     {
     Load,
     Save
     }
    
     public class SaveStoreResponse
     {
     private bool success = true;
     private string errorMessage;
    
     public bool Success
     {
     get { return this.success; }
     set { this.success = value; }
     }
    
     public string ErrorMessage
     {
     get { return this.errorMessage; }
     set { this.errorMessage = value; }
     }
    
     public ConfirmationList ConfirmationList { get; set; }
     }
    }

    AjaxStoreResult 在 CustomerController 中的使用:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Mvc.Ajax;
    using CooliteMVC.Models;
    using CooliteMVC.Helper;
    using Coolite.Ext.Web;
    
    namespace CooliteMVC.Controllers
    {
     public class CustomerController : Controller
     {
     //
     // GET: /Customer/
    
     public ActionResult Index()
     {
     ViewData["Title"] = "Customer List";
     ViewData["Message"] = "Welcome to Coolite MVC! My name is Bruce.";
     return View();
     }
    
     public ActionResult List(int limit, int start, string dir, string sort)
     {
     Random rand = new Random();
     IList<Customer> list = new List<Customer>();
     for (int i = start; i < start + limit; i++)
     list.Add(new Customer
     {
     CustomerID = "Customer" + i,
     Address = "Address" + i,
     City = "City" + rand.Next(1000),
     CompanyName = "Com" + rand.Next(1000),
     ContactName = "Contract" + rand.Next(1000),
     ContactTitle = "Title" + rand.Next(1000),
     Country = "Country" + rand.Next(1000),
     Email = rand.Next(1000) + "@live.com",
     Fax = rand.Next(1000).ToString() + rand.Next(1000),
     Mobile = rand.Next(1000).ToString() + rand.Next(1000),
     Notes = "Notes" + rand.Next(1000),
     Phone = "Phone" + rand.Next(1000),
     Region = "Region" + rand.Next(1000),
     TranDate = DateTime.Now.AddDays(rand.Next(30))
     });
     return new AjaxStoreResult(list, 100);
     }
    
     public ActionResult Save()
     {
     AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);
     try
     {
     StoreDataHandler dataHandler = new StoreDataHandler(Request["data"]);
     ChangeRecords<Customer> data = dataHandler.ObjectData<Customer>();
    
     foreach (Customer customer in data.Deleted)
     {
     //db.Customers.Attach(customer);
     //db.Customers.DeleteOnSubmit(customer);
     }
     foreach (Customer customer in data.Updated)
     {
     //db.Customers.Attach(customer);
     //db.Refresh(RefreshMode.KeepCurrentValues, customer);
     }
     foreach (Customer customer in data.Created)
     {
     //db.Customers.InsertOnSubmit(customer);
     }
     }
     catch (Exception e)
     {
     ajaxStoreResult.SaveResponse.Success = false;
     ajaxStoreResult.SaveResponse.ErrorMessage = e.Message;
     }
     return ajaxStoreResult;
     }
     
     }
    }

    頁面的關(guān)鍵代碼:

     <ext:Store ID="dsCustomers" runat="server" >
     <Proxy>
     <ext:HttpProxy Url="/Customer/List" Method ="GET" />
     </Proxy>
     <UpdateProxy>
     <ext:HttpWriteProxy Url="/Customer/Save" />
     </UpdateProxy>
     <Reader>
     <ext:JsonReader ReaderID="CustomerID" Root="data" TotalProperty="totalCount">
     <Fields>
     <ext:RecordField Name="CustomerID" SortDir="ASC" />
     <ext:RecordField Name="CompanyName" />
     <ext:RecordField Name="ContactName" />
     <ext:RecordField Name="Email" />
     <ext:RecordField Name="Phone" />
     <ext:RecordField Name="Fax" />
     <ext:RecordField Name="Region" />
     <ext:RecordField Name="TranDate" Type="Date" />
     </Fields>
     </ext:JsonReader>
     </Reader>
     <BaseParams>
     <ext:Parameter Name="limit" Value="15" Mode="Raw" />
     <ext:Parameter Name="start" Value="0" Mode="Raw" />
     <ext:Parameter Name="dir" Value="ASC" />
     <ext:Parameter Name="sort" Value="CustomerID" />
     </BaseParams>
     <SortInfo Field="CustomerID" Direction="ASC" />
     </ext:Store>
    我們可以看到其實就是Url的寫法不同而已:
     <ext:HttpProxy Url="/Customer/List" Method ="GET" />
     <ext:HttpWriteProxy Url="/Customer/Save" /> 
    詳細頁面代碼跟第一章差不多,這里不列出來。 

    聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    Coolite Cool Study 3 MVC + Coolite 的實現(xiàn)代碼

    Coolite Cool Study 3 MVC + Coolite 的實現(xiàn)代碼: 因為默認的 MVC 的樣式文件里對于的 table 和 其他相關(guān)樣式(h1~h6) 與Coolite有沖突,會導(dǎo)致GridPanel走樣,大家記得先把那個table 和 h1~h6的樣式清除掉才看到GridPanel的帥臉面 … 項目文件分布: 關(guān)于Coolite在MVC中的配置文件跟一般
    推薦度:
    標(biāo)簽: cool study mvc
    • 熱門焦點

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 国产精品 日韩欧美| 四虎影院国产精品| 精品人妻伦九区久久AAA片69| 久久久久99精品成人片试看| 国产一区麻豆剧传媒果冻精品| 91精品成人免费国产| 亚洲欧美日韩精品专区| 国产99视频精品免费视频76| 国产欧美日韩综合精品一区二区| 欧美精品国产一区二区三区| 亚洲国产精品人久久| 大桥未久在线精品视频在线| 亚洲精品国产首次亮相| 免费国产在线精品一区| 国产成人精品综合在线观看| 精品免费tv久久久久久久| 麻豆亚洲AV永久无码精品久久| 四虎亚洲国产成人久久精品| 精品国产婷婷久久久| 办公室久久精品| 国产精品1024香蕉在线观看 | 黑巨人与欧美精品一区| 日韩精品国产自在久久现线拍| 91精品国产综合久久久久久| 亚洲国产精品无码久久久不卡| 无码人妻一区二区三区精品视频 | 国产亚洲精品无码拍拍拍色欲| 色偷偷888欧美精品久久久| 99国产精品久久| 大桥未久在线精品视频在线 | 国产99视频精品免费专区| 久久久国产乱子伦精品作者| 久久亚洲精精品中文字幕| 欧美精品VIDEOSSEX少妇| 久久er99热精品一区二区| 无码人妻精品一区二区| 人妻精品久久无码区| 久久精品国产亚洲av高清漫画| 久久亚洲精品国产精品| 国产人妖乱国产精品人妖| 国产精品高清视亚洲精品|