JJ Wang

@JJayWang

程式開發筆記 有空寫寫 沒空也寫寫 總之 要保持住寫寫

Joined on Sep 26, 2022

  • ASP.NET MVC 的 Filter 可以在 Request 進入 Controller 及執行 Action 的過程中執行特定邏輯,例如:權限驗證、錯誤攔截。 Filter 類型 Authorization Filters:進入 Controller 及執行 Action 之前執行驗證、授權判斷。 Action Filters:在執行 Action 之前或之後,執行Filter邏輯。 Result Filter:在執行 View 之前或之後,執行Filter邏輯。 Exception Filters:處理未攔截的 Exception。 可設定Filter的位置 全域 Filter
     Like  Bookmark
  • 前言 對 ViewData、ViewBag、TempData 做簡單的整理,並且透過實作來熟悉。 範例準備 建立範例用的 DataController和 Index、Read 的 Action,再建立對應的 View (Index.cshtml、Read.cshtml)。 DataController.cs public class DataController : Controller {
     Like  Bookmark
  • 建立範例 Model public class Staff { [Required, StringLength(10, MinimumLength = 1)] public string Name { get; set; } [Range(0, 100, ErrorMessage = "數值需介於0到100之間")] public int Number { get; set; }; [EmailAddress] public string Email { get; set; } [Phone]
     Like  Bookmark