發表文章

[電繪]:Rattus rattus-黑鼠

圖片
  In some eras, rats represented the plague and were despised creatures, but in my eyes, humans and rats are no different. -- 在某些時代裡,老鼠代表著瘟疫,是人們唾棄的生物,然而在我眼裡,人與老鼠並無不同。

[電繪]:Rattus rattus-黑鼠

圖片
  In some eras, rats represented the plague and were despised creatures, but in my eyes, humans and rats are no different. -- 在某些時代裡,老鼠代表著瘟疫,是人們唾棄的生物,然而在我眼裡,人與老鼠並無不同。

[Electron] ElectronNet Asp.net Core build error:Error: Cannot find module 'fs/promises'

圖片
 問題: 最近在打包electron的時候遇到了「 Cannot find module 'fs/promises' 」的問題,爬了網路上許多文章,都是說nodejs的版本過低導致的,只要把nodejs的版本升至14以上就可以解決這個issue,但我的nodejs版本是14.17.1依然無法解決此問題。 解決方法: 後來我是將「ElectronNET.CLI」的版本升至13.5.1,目前已解決問題,在此紀錄。 cmd: dotnet tool update --global ElectronNET.CLI --version 13.5.1 我的套件版本如下: ElectronNET.CLI--version: 13.5.1 ElectronNET.API--version: 13.5.1 dotnet core : 5 node js: 14.17.1

[電繪]:蜥蜴

圖片
  嘗試畫了我最愛的生物"蜥蜴",不過配色有點怪...

[電繪]#橘貓

圖片
  嘗試畫了橘貓的側臉,感覺配色有些奇怪。

[電繪]:寒冬

圖片
  臨摹了電子報關於寒流的一張照片,希望大家這次的寒流都可以穿的保暖。

[電繪]:橘貓

圖片
  每到下午時分,我們家的圍牆上就會有個固定的常客來睡午覺。

[電繪]:#棒球#統一#陳重羽

圖片
  今天嘗試畫了女友最愛的棒球員之一,陳重羽(第一次畫人,請球迷見諒😅)。

[電繪]:狐狸犬

圖片
  狐狸犬是女友養的第一隻寵物,在我們大學三年級的時候去做了天使,希望這張畫能提醒我們要黑好珍惜那些飛逝美好的時光。

[電繪]:熊狸

圖片
  我一直有想用繪圖板畫圖的想法,不過由於本人很懶所以一直沒有付出行動XD,感謝女友幫我付出行動,在我生日的時候給了我一個驚喜!畫了個熊狸做個紀念。

[Razor]View傳遞viewdata給PartialView

圖片
需求: 想要在一個view傳值給另一個view。 假設我今天有兩個view,一個是Index(圖一),一個是BView(圖二),我們可以看到BView有一個ViewBag.Value,但目前這個ViewBag並沒有值,我們要如何從Index將自鑽value的"apple"傳給BView呢? 圖一 圖二 實作: (一)new 一個ViewDataDictionary物件來傳遞value: @{     var value = "apple"; } <h1>我是Index</h1> <hr /> @Html.Partial("BView", new ViewDataDictionary { { "Value", value } }) 結果: 成功將apple傳遞給了BView。

[Enum]依照Int 值 取得Enum的描述

圖片
 需求: 目前我有一個類型為int的變數value,值為1(如圖一);有一個列舉TestEnum(如圖二),那麼該如何利用這麼變數value取的Enum的Description = "測試B"呢? 圖一 圖二 實作: (一)寫一個"依照Int 值 取得Enum的描述"的擴充方法: 引用: using System.ComponentModel.DataAnnotations;   /// <summary>         /// 依照Int 值 取得Enum的描述         /// </summary>         /// <typeparam name="T">泛型</typeparam>         /// <param name="obj">列舉物件</param>         /// <returns></returns>         public static string GetEnumDescriptionByInt<T> (this object obj)         {             int value;             if (obj == null)             {                 return string.Empty;             }             if (!int.Try...

[JQuery]簡單的table 排序功能

圖片
需求: 使用頁面資料內容,點擊<th>時會遞增,遞減排序所屬<td>內容。 實作: 引用: <!--引用 dataTables css --> <link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" /> <!--引用jQuery--> <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script> <!--引用dataTables--> <script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"> html: table class給JQ_DataTable,不想排序的欄位,class給no-sort。 <table class=" JQ_DataTable ">     <thead>         <tr>             <th class=" no-sort ">項次</th>             <th>內容</th>         </tr>     </thead>     <tbody>         @for (var i = 1; i <= 10; i++)         {             <tr> ...

[C#]將Model轉UrlAction字串方法

圖片
 需求: 使用@Url.Action()的時候,有時候要接的參數太多,因此我就想有沒有辦法可以直接將以有的modal自動轉為RouteValueDictionary帶回controller。 情境: 我有一個model TestModel (圖一),我想把Action Index 的model透過A標籤用@Url.Action()傳遞到Action  Test (圖二) 圖一 圖二 實做: (一)建立一個UrlHelper 來將物件轉換成RouteValueDictionary:  /// <summary>         /// 物件轉換成RouteValueDictionary         /// </summary>         /// <typeparam name="T">泛型</typeparam>         /// <param name="obj">物件</param>         /// <returns></returns>         public static RouteValueDictionary ObjectToRouteValueDictionary <T>(T obj)         {             var rvDic = new RouteValueDictionary();             foreach (var property in obj.GetType().GetProperties())             {           ...

[C#]依照屬性名稱取得模型欄位值

圖片
 需求: 取得物件模型裡,某一個屬性欄位的值。 ex: 我目前有一個 模型TestModal (圖一),並new 出了一 個TestModal,分別給 A、B 屬性自己的值(圖二),假設今天想要 只拿到B屬性欄位的值 該如何辦到呢? (圖一) (圖二) 實作: (一)寫一個依照屬性名稱取得欄位值的方法:   /// <summary>         /// 依照屬性名稱取得模型欄位值         /// </summary>         /// <typeparam name="T1"></typeparam>         /// <param name="name">欄位名稱</param>         /// <param name="t1"></param>         /// <returns></returns>         public static object GetValueByPropertyName <T1>(this string name, T1 t1)         {             return t1.GetType().GetProperty(name).GetValue(t1);         } (二)使用GetValueByPropertyName()取得Test裡屬性B的值 static void Main(string[] args)         {             var test = new TestModal...

[Ajax]Return-Partial-View-as-JSON

圖片
 需求: 有時候使用Ajax有return PartialView的需求,但卻又只能傳送Json,不能return PartialView,這時候就只能把想回傳的view 轉成字串了。 實作: Index: 我們簡單寫一個頁面,裡面有一個button,並寫一個click事件,在按下之後會在TOP與BOTTOM div之前回傳我們所想加入的view。 <div>     <button onclick="TestBtn()">回傳patrialView</button> </div> <div>TOP</div> <div id="PartialDiv"></div> <div>BOTTOM</div> @Html.Hidden("TestViewUrl",Url.Action("TestViewToString", "Home")) @section scripts {     <script>         function TestBtn() {             $.ajax({                 url: $('#TestViewUrl').val(),                 type: "POST",                 success: function (e) {                     $('#PartialDiv').html(e.TestView);                 }, ...

[MVC]在modal上層加blockUI

圖片
 需求: 有時候需要在modal顯示的時候,也想使用blockUI來鎖住畫面不讓使用者使用,但卻會發現雖然blockUI有成功顯示,但卻是顯示在modal的下層。 實作: (1)在modal上加上button來測試blockUI @*訊息Modal*@ <div id=" confirmModal " class="modal fade" tabindex="-1" role="dialog">     <div class="modal-dialog">         <div class="modal-content">             <div class="modal-header" id="confirmcontext">                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>                 <h4 id="confirmTitle" class="semi-bold">訊息</h4>             </div>             <div id="confirmBady" class="modal-body land-inline-striped"></div>             <div class="modal-footer text-left">               ...

[Enum] 取得列舉描述 GET Enum Description

圖片
 需求: 取得Enum Description(描素)的值。 實作: (1)建立EnumHelper:   /// <summary>         /// 取得列舉描述         /// </summary>         /// <param name="obj">列舉物件</param>         /// <returns></returns>         public static string GetDescription(this Enum obj)         {             var objName = obj.ToString();             var t = obj.GetType();             var fi = t.GetField(objName);             var arrayDescription = (DisplayAttribute[])fi.GetCustomAttributes(typeof(DisplayAttribute), false);             return arrayDescription == null ? string.Empty : arrayDescription[0].Description;         } (2)使用範例:  var enumDescription = LoginType.login.GetDescription();

[C#]String處理 回傳只有數字的字串

圖片
 需求: 傳入一個string,過濾掉不是數字的字元,回傳只有數字的字串。 實作: 方法一:用IsDigit()的方式過濾,回傳只有數字的字串          /// <summary>         /// Stripping out non-numeric characters in string         /// </summary>         /// <param name="str"></param>         /// <returns></returns>         public static string GetNumbers(string str)         {             return new string(str.Where(c => char.IsDigit (c)).ToArray());         } 方法二:用TryParse()的方式過濾,直接將字串轉為Int回傳           /// <summary>         /// string to int         /// </summary>         /// <param name="str"></param>         /// <returns></returns>         public static i...

[Mvc]簡單的確認訊息彈出視窗 confirmModal

圖片
 需求: 跳出可以自訂樣式的視窗,而不是用alert()的方式顯示訊息。 實作: view 在view加上自訂的訊息Modal,並寫一個button,新增click事件來測試是否有用。 <div>     <button onclick=" ShowMessage ('你想要傳的訊息');">         開啟確認訊息     </button> </div> @*訊息Modal*@ <div id="confirmModal" class="modal fade" tabindex="-1" role="dialog">     <div class="modal-dialog">         <div class="modal-content">             <div class="modal-header" id="confirmcontext">                 <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>                 <h4 id="confirmTitle" class="semi-bold">訊息</h4>             </div>             <div id="confirmBady" class="modal-body land-inline-striped"></div>   ...