顯示具有 ASP.NET MVC 標籤的文章。 顯示所有文章
顯示具有 ASP.NET MVC 標籤的文章。 顯示所有文章

2017/1/9

MVC Code-First 設定欄位Unique

Author: Willie Chou
Date:2017/01/09


需求¨:利用CodeFirst 的計巧將Table的某個欄位設定為Unique
作法:

1. 引用 using System.ComponentModel.DataAnnotations.Schema;
2. 加入[Index .....] , 如附圖


3, 執行 Add-Migration >> Update-Database
4. 結果如附圖




以上,謝謝



2017/1/6

MVC woff 404 error

Author: Willie Chou
Date: 2017/01/06

近日開發時遇上網站無法存取  .woff 的問題,檢查了資料夾內確有此檔!
到底是什麼原因呢?


經查Stack Overflow 後原來出錯在Header的設定,它提供了二種解決方式! 請大家直接連造過去即可得到答案!

Why is @font-face throwing a 404 error on woff files?

2017/1/3

Linq 回傳重覆資料

Linq Return Duplicate Rows 

Author: Willie Chou
Date: 2017/01/03

今日解決了一個Linq 回饋多筆重覆資料的問題,經上網查找後此文(Link)給了個靈感,原來是我在設定Model的時候指定給了Key欄位不正確的問題 (詳細的原因可以參考連結文章)。

Error




修正Model, 指定正確的Key於欄位上


再執行 Add-Migration >> Update-Database

問題修復! 大功告成!

*註:這裡我因為是自訂的Database View因此在 Migration 時下的指令為 Add-Migration fixIssue -IgnoreChanges


Reference:
http://www.itworld.com/article/2833108/development/linq-in--net-returning-duplicate-rows-from-a-working-sql-view--solved-.html






2016/12/30

Asp.net MVC call Jasper report via REST v2 service

Author: Willie Chou
Date: 2016/12/30


Directly call jasper report via http request.
Please see below scripts.
Hope this is help for you ! Happy New Year !

Please note! the variable _ReportURL format
  _ReportURL  = http://<web url>/jasperserver/rest_v2/reports

  public  ActionResult PrintPO(string POEntry)
        {

           
            //_ReportURL = System.Web.Configuration.WebConfigurationManager.AppSettings["ReportURL"];

            //_ReportUser = System.Web.Configuration.WebConfigurationManager.AppSettings["ReportUser"];

            //_ReportUserPWD = System.Web.Configuration.WebConfigurationManager.AppSettings["ReportUserPWD"];


            String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(_ReportUser + ":" + _ReportUserPWD));

            string URL = _ReportURL + "/report.pdf?po=" + POEntry;



            CookieContainer myContainer = new CookieContainer();

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);

          

            request.CookieContainer = myContainer;

            request.PreAuthenticate = true;                       

            request.Headers.Add("Authorization", "Basic " + encoded);

            HttpWebResponse response = (HttpWebResponse)request.GetResponse();



            var fileBytes = response.GetResponseStream();

            string filename = String.Format("PO{0}_{1}.pdf", POEntry, DateTime.UtcNow.ToString("yyyMMddHHmmssfff"));

            return File(fileBytes, response.ContentType,filename); //preview in browser please remove filename

        }



Result as below pix.

2015/5/29

ASP.NET MVC 教學參考文章

Author: Willie
Creation Date:2015/05/29
Update Date: 2016/12/28

不解釋,我只能說!!!太強大了,這裡的技巧及觀念不見得是可以在坊間書中可以看得到的,強力推!!

mrkt的程式學習筆記

如果要學ASP.NET  MVC這位佛心來著的部落格大大是必看的


Update  :

近來開始MVC的實作,常用到的有還是在mrkt的程式學習筆記
並且使用這本書:ASP.net MVC5 網站開發美學
另外,也需要留意搭配前端工具easyUI 相關的操作,也歡迎大家能推一些網站/文章給我