@section HeaderJS{ <link rel="stylesheet" type="text/css" href="../Content/css/indexstyle.css" /> <link rel="stylesheet" href="../Content/js/ZTree/css/zTreeStyle/zTreeStyle.css"> <script src="../Content/js/ZTree/js/jquery.ztree.all-3.5.js"></script> <script src="../Scripts/tableExport.js"></script> <script src="../Scripts/jquery.base64.js"></script> <script src="../../Content/js/public.js"></script> <script type="text/javascript">}
從以上例子可以看出,這個方法可以用來載入 .js, .css 檔案到 .cshtml 檔案中。 你可以定義自己的 .js 檔案, 然後用這種方式載入進來。這樣你就可以在這個檔案裡面使用 .js 檔案中的函數了。 如 public.js 檔案如下:
//格式化Json資料中的時間function formatTime(dateTime) { var date = new Date(parseInt(dateTime.replace("/Date(", "").replace(")/", ""), 10)); var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1; var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate(); var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); var min = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(); return date.getFullYear() + "-" + month + "-" + currentDate + " " + hour + ":" + min;}
這樣就可以直接在 HeaderJS 這個 section 中使用 formateTime() 函數。
zTree 的使用。
在另外文章中講解。
ASP.NET MVC 3 匯出匯入 HTML table 到 csv 檔案
在另外文章中講解。
HTML checkbox 全選和全不選的實現
function changeCheckBoxState() { $("#chkcheckall").click(function () { $('.radio').prop("checked", this.checked); }); }
這裡有個問題是不能使用 checkbox 的 change 事件。 在 IE 中, 第一次點中 checkbox 並不觸發 change 事件, 直接用 click 事件繞開這個問題。
判斷瀏覽器是否是 IE
function isIE() { //ie? if (!!window.ActiveXObject || "ActiveXObject" in window) { return true; } if (navigator.userAgent.split(";")[1].toLowerCase().indexOf("msie") == "-1") { return false; } else { return true; } }
這個又敗給 IE 了, IE 11 的 userAgent 裡面根本沒有 "ie" 字元, 這得坑掉多少人。第一個 if 語句是用來判斷是否是 IE 11 的。
首先, Controller
在 Controller 中,向 view 返回的方式有很多, 比如:
return Content("ok");
// // 摘要: // 使用字串建立一個內容結果對象。 // // 參數: // content: // 要寫入到響應的內容。 // // 返回結果: // 內容結果執行個體。return Content("ok");// // 摘要: // 建立 System.Web.Mvc.JsonResult 對象,該對象使用指定 JSON 請求行為將指定對象序列化為 JavaScript 物件標記法 // (JSON) 格式。 // // 參數: // data: // 要序列化的 JavaScript 對象圖。 // // behavior: // JSON 請求行為。 // // 返回結果: // 將指定對象序列化為 JSON 格式的結果對象。return Json(data, JsonRequestBehavior.AllowGet);// // 摘要: // 建立一個將視圖呈現給響應的 System.Web.Mvc.ViewResult 對象。 // // 返回結果: // 將視圖呈現給響應的視圖結果。return View();// // 摘要: // 建立一個呈現分部視圖的 System.Web.Mvc.PartialViewResult 對象。 // // 返回結果: // 分部視圖結果對象。return PartialView();
這個需要去看 MSDN 文檔, 隨時都會用到這些方法, 需要知道他們到底是幹嘛的。 在 System.Web.Mvc.Controller 中有介紹。
Entity Framework 是一款很好用的 OA 架構。 非常容易上手, 如果項目小, 不想用資料庫, 可以利用 EF 來產生本地的 .mdb 檔案, 作為資料存放區工具。 遇到的一個問題是,在串連遠端資料庫是, 伺服器總管能夠連到資料庫, 但是 EF 老是報無法開啟串連的錯誤。 這肯定是 url 串連資訊設定錯誤。
<connectionStrings> <!--<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-Mvcpro1-20141022154431;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-Mvcpro1-20141022154431.mdf" providerName="System.Data.SqlClient" />--> <!--<add name="hour1Entities" connectionString="metadata=res://*/Models.Model1.csdl|res://*/Models.Model1.ssdl|res://*/Models.Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=hour1;user id=sa;password=123456;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /> <add name="hourEntities" connectionString="metadata=res://*/Models.Hour.csdl|res://*/Models.Hour.ssdl|res://*/Models.Hour.msl;provider=System.Data.SqlClient;provider connection string="data source=.;initial catalog=hour1;user id=sa;password=123456;multipleactiveresultsets=True;application name=EntityFramework"" providerName="System.Data.EntityClient" />--> <add name="complaintSysDBEntities" connectionString="metadata=res://*/complaintSys.csdl|res://*/complaintSys.ssdl|res://*/complaintSys.msl;provider=System.Data.SqlClient;provider connection string="data source=114.80.154.68,32433;initial catalog=complaintSysDB;user id=sa;password=12344321;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient"/> </connectionStrings>