標籤

ASP.NET MVC (29) Visual C# (15) JQuery (10) Plugins (8) JQuery Plugins (6) JavaScript (6) MySQL (5) CSS (4) LinQ (4) Mac OS (4) CentOS (3) Design Pattern (3) Entity Framework (3) IIS (3) Python (3) Windows (3) php (3) Docker (2) LAMP (2) SQL Server (2) WCF (2) .NET (1) .NET Core (1) AWS (1) Browser (1) GIS (1) IE (1) Internet Security (1) Linux (1) Platform (1) React (1) SEO (1) Testing (1) VMware (1) Windows 7 (1) cookie (1) curl (1) laravel (1) phpBB (1) session (1) 中古屋 (1) 透天 (1) 閒言閒語 (1) 面試 (1) 鳥松 (1)

2011年4月17日 星期日

[ASP.NET MVC]直接在Controller中取得檔案的絕對路徑(Content or Script path)

通常我們在View中都會使用:1. Html Helper 2.Url Helper
那假設我們想要在Controller中直接取得Content或Script的絕對路徑(path)呢?


public ActionResult Image(string id)
{
    var dir = Server.MapPath("/Images");
    var path = Path.Combine(dir, id + ".jpg");
    return base.File(path, "image/jpeg");
}

效能有差一點點就是了...

參考資料:

Can an ASP.Net MVC controller return an Image?

http://stackoverflow.com/questions/186062/can-an-asp-net-mvc-controller-return-an-image



[ASP.NET MVC]將form放在JqueryUI Dialog中post與validation失效的問題

這個問題害我卡了一個下午,如果我們將MVC的FORM使用JqueryUI Dialog包起來的話,他會把FORM移出Dialog,只要下面這個指令就可以解決:
   $('#dialog').parent().appendTo($('#PostForm'));

參考資料:

jQuery validation error inside the jQuery.UI.Dialog

2011年4月16日 星期六

[JQuery] Jquery 基礎操作

1. 設定select option的選取值




$('#selectA option[value=C]').attr('selected', 'selected');


2. 讀取Table的值,放到input的顯示文字中:

< tr id ="tridFoo200500000001" >< td class="tdGoodNAME">桶三科學粥< /td>< /tr>

$("#GoodNAME").val($("#tridFoo200500000001 .tdGoodNAME").text());

3. 取得input text 輸入方框內的文字

$("#SearchStudentNotInClass").val() 

4. 取得被div夾住的文字(12345678)

$("#DivInClass").text() 

2011年4月14日 星期四

[Regular Expression]常用的正規式判斷

EMail;/^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/

日期yyyy/MM/dd:        [RegularExpression(@"^(19|20|21)\d\d[/](0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])$", ErrorMessage = "日期格式錯誤")]

2011年4月9日 星期六

[Visual C#] 正規式引發錯誤訊息"- 相反順序的 [x-y] 範圍。" Regular Expression Regex

System.ArgumentException  Regex [x-y] range in reverse order
==============================
起因是我的正規式判斷為:[A-Za-z0-9_- %]{8,15}
改成:[A-Za-z0-9_ %-]{8,15} 就OK了


猜測是如果_-後面接上特殊符號會出錯

2011年4月8日 星期五

[Visual C#] 正規式的例外符號 Regular Expression Regex

在正規式中,除了 .$ ^ { [ ( | ) * + ? \ 這幾個符號有特別意義以外,其他的符號都是直接寫直接配對,
所以如果要配對上述的幾個符號,除了加上反斜線(\)外,也可以使用轉換符號(unicode):



.點 \u002E
$美元\u0024
^次方 \u005E
{左大括 \u007B
[左中括[ \u005B
(左小括( \u0028
|直線 \u007C
)右小括 \u0029
*星號 \u002A
+加號 \u002B
?問號 \u003F
\反斜線 \u005C


範例:
例如要比對某個字串是否有符合【http://www.youtube.com/watch?v=】或【https://www.youtube.com/watch?v=】這兩種網址,正規式為:
【^http(s?)://www\u002Eyoutube\u002Ecom/watch\u003Fv=$】


不使用轉換符號也可以:
【^http(s?)://www\.youtube\.com/watch\?v=$】


MSDN:http://msdn.microsoft.com/en-us/library/30wbz966.aspx

2011年4月7日 星期四

[TinyMCE] ASP.NET MVC View中TextArea使用Client Validation 衝突問題

Keyword:TinyMCE ASP.NET MVC Client Validation TextArea
========================

如果我們所驗證的欄位為Not Null,則就算我們在客戶端的TextArea中打上文字,第一次送出表單在客戶端驗證會出錯,但是第二次就可以送出,這是由於TinyMCE是使用暫存機制,只有在表單送出時才會把編輯的內容複製到TextArea中(在這之前為空)。

解決方法,加入以下程式碼:

    //為了解決TinyMCE與ClientValidation衝突的問題,修正要送出兩次改為一次。
$("input[type='submit']").click(function () {
            tinyMCE.triggerSave();
        });