跳到主要內容

發表文章

[MVC] ASP.NET MVC 專案加上 API 說明頁面

新增 Empty 專案,參考勾選 MVC 和 Web API  加入 具有讀取/寫入動作的 Web API 控制器 瀏覽網頁http://localhost:xxx/api/Get 會因為不同瀏覽器顯示不同格式,修改  App_Start\WebApiConfig.cs ,加入以下這一行,讓 ASP.NET Web API 永遠只回應 JSON 格式 GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();  在每個 function 增加描述 ,打 /// 會自動產生 <summary> 產生專案的XML文件  「專案屬性」→ 「建置」→  勾選「XML 文件檔案」,路徑改  「 App_Data\XmlDocument.XML 」 →  建置專案就會自動在 App_Data 目錄下產生 XmlDocument.XML 檔案 NuGet 安裝 Microsoft.AspNet.WebApi.HelpPage 套件 開啟 Areas/HelpPage/App_Start/HelpPageConfig.cs ,把以下程式碼註解取消 config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml"))); 重點是確認路徑是否正確  "~/App_Data/XmlDocument.xml" 瀏覽 http://localhost:xxx/Help  參考連結 如何在 ASP.NET MVC 4 專案加上 Web API 與 API 說明頁面 進入 ASP .NET MVC 5 的世界 (台北場) 如何讓 ASP.NET Web API 無論任何要求都回應 JSON 格式

[MVC] Code First 避免DB資料遺失

利用Nuget安裝  Migrations Nuget套件管理員 -->  套件管理器主控台 下載套件,輸入指令: Enable-Migrations 增加 Migrations 資料夾及其檔案 修改  configuation.cs 修改 public Configuration() 如下圖  public Configuration()  {             AutomaticMigrationsEnabled = true;  //避免資料遺失             AutomaticMigrationDataLossAllowed = true; //避免SP遺失  } 更新DB時,可以下指令: Update-Database 參考網頁 Code First Migrations更新数据库结构(数据迁移)保证数据不丢失 [C# and EF] Tutorial: Entity Framework Code First Migrations 2/2

[C#] 匯出Excel

[ .CS ] #region 匯出Excel     public override void VerifyRenderingInServerForm(Control control)     {         //處理'GridView' 的控制項 'GridView' 必須置於有 runat=server 的表單標記之中     }     protected void btnExcel_Click(object sender, EventArgs e)     {         gvw_Execl.Visible = true;         Response.Clear();         Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode("Lettrt.xls"));         Response.ContentType = "application/vnd.ms-excel";         Response.Charset = "";         Response.Write("<style type=text/css>");         Response.Write("td{mso-number-format:\"\\@\";}"); //將所有欄位格式改為"文字"         Response.Write("</style>");         //關閉ViewState         Enabl...

[T-SQL] ROLLBACK TRANSACTION

使用 ROLLBACK TRANSACTION 清除交易開始之後的所有資料修改,或清除儲存點之前的所有資料修改。 SET XACT_ABORT ON BEGIN TRANSACTION BEGIN TRY -- 執行的程式碼 END TRY BEGIN CATCH         --如果程式執行有錯誤時,將成功修改的資料全部還原 IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION RETURN END CATCH SET XACT_ABORT OFF IF @@TRANCOUNT > 0 COMMIT TRANSACTION 參考連結 http://msdn.microsoft.com/zh-tw/library/ms181299.aspx http://wl-ldy.iteye.com/blog/1161744 http://www.dotblogs.com.tw/dc690216/archive/2009/11/06/11455.aspx

[JavaScript] 利用 Regex 截取(取代)文字

利用Regex 取愈取代的片段 [HTML] < script type ="text/javascript">         function RerutnStr() {             //<form xxx> 開頭             var str = document.getElementById( "txtStr" ).value;             var pattern = new RegExp( '<form[^>]*>' );             var result = str.replace(pattern, '' );             //</form> 結尾             pattern = new RegExp( '</form[^>]?>' );             result = result.replace(pattern, '' );              document.getElementById("divView").innerText = ...

[C#] Enum 列舉

[.CS]  protected enum myType : int {         Women = 0,         Boy = 1,         other = 3 } protected void btnOK_Click(object sender, EventArgs e) {               myType str = (myType)Enum.Parse(typeof(myType), txtInput.Text.Trim());         // (int) myType  , enum 的值        // .ToString(),enum 的項目         lblResult.Text = str.ToString(); } 參考連結 http://www.dotblogs.com.tw/dc690216/archive/2009/09/16/10666.aspx