標籤

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月29日 星期五

[JavaScript] 字串去除空白字元 (string Trim function)

JavaScript 是沒有內建Trim Function的,也就是將字串頭尾空白去掉的功能,但是我們可以這樣實作一個Function:


function trim(s) {  
  return s.replace(/^\s*|\s*$/g,"")  
}  

據說這個版本更快:

// Author: Ariel Flesler  
// http://flesler.blogspot.com/2008/11/fast-trim-function-for-javascript.html  
// Licensed under BSD  
function myBestTrim(str) {  
  var start = -1,  
  end = str.length;  
  while (str.charCodeAt(--end) < 33);  
  while (str.charCodeAt(++start) < 33);  
  return str.slice(start, end + 1);  
}; 


Refrence:
http://jsgears.com/thread-132-1-1.html

http://www.ijavascript.cn/jiaocheng/javascript-trim-145.html

2011年4月27日 星期三

[ASP.NET MVC] 禁止停用IE的網頁資料快取機制 (disable browser cache)

只要加上以下程式碼:

public class NoCacheAttribute : System.Web.Mvc.ActionFilterAttribute
    {
        public override void OnResultExecuting(System.Web.Mvc.ResultExecutingContext filterContext)
        {
            filterContext.HttpContext.Response.Cache.SetValidUntilExpires(false);

            filterContext.HttpContext.Response.Cache.SetRevalidation(HttpCacheRevalidation.AllCaches);

            filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            filterContext.HttpContext.Response.Cache.SetNoStore();

            base.OnResultExecuting(filterContext);
        }
    }


之後在任何的Action或Class上方加上[NoCache]即可;

[NoCache]
public class AController : Controller
{
    [NoCache]
    public ActionResult Index()
    {
        return View();
    }
}


Reference:

asp.net mvc disable browser cache

[JQuery Plugins] 使用JQuery UI datepicker作為行事曆 (Event Calendar)

有幾篇文章不錯,可以看看人家怎麼實作:

The beforeShowDay callback allows you to do this. It is a function that takes a Date as a parameter and returns an array with [0] being true if the date is selectable, false if not, [1] being a CSS class to apply to that date cell, [2] being an optional popup tooltip for the date.

$('#mydate').datepicker({beforeShowDay:
 highlightOdds});

function highlightOdds(date) {
     
 return [true, date.getDate() % 2 == 1 ? 'odd' : ''];
}




jQuery UI Datepicker with jQuery tipsy





[JqueryUI] Date Picker - color cell day


JQuery UI 官方連結



[TinyMCE] JQuery UI dialog 相衝問題

如果把TinyMCE放到dialog ,非IE就會變成唯讀,目前還沒找到適當的解決方式,

$("#dialogCommentMessage").dialog({
            autoOpen: false,
            show: "blind",
            hide: "explode",
            height: "400",
            width: "800", 
            modal: true,
              open: function (event, ui) {
                  tinyMCE.execCommand('mceAddControl', true, 'NContent');
              },
              close: function (event, ui) {
                  tinyMCE.execCommand('mceRemoveControl', true, 'NContent');
              }

        });



相關文章

http://www.flyingjolly.com/2010/10/tinymce-and-jquery-dialog/

http://stackoverflow.com/questions/2082599/tinymce-only-readable-in-jquery-ui-dialog

http://forum.jquery.com/topic/tinymce-dialog-issue

http://forgottencode.wordpress.com/2009/07/22/jquery-dialog-and-tinymce-not-working/

http://stackoverflow.com/questions/752313/tinymce-and-jquery-ui-dialog-working-nicely

http://tinymce.moxiecode.com/tryit/jquery_plugin.php

2011年4月26日 星期二

[ASP.NET MVC] 升級MVC2 至 MVC3的工具 - ASP.NET MVC 3 Application Upgrad

ASP.NET MVC 3 Application Upgrad

這裡可以下載:
http://aspnet.codeplex.com/releases/view/59008

目前用了之後沒甚麼問題,有問題再說...

[ASP.NET MVC] 如何在使用JQuery載入部分檢視(Partial View)

How to load the Partial View using JQuery in ASP.NET MVC?
============================
假設部分檢視的路徑為~/Manager/Student/3,且一開始就載入部分檢視,只要在script中定義function:


jQuery(document).ready(function () {
    ajax_updatePartial('<%= Url.Content("~/Manager/Student/")%>' + '<%: Model.Id %>');
});
        
function ajax_updatePartial(path){
  $.ajax ({
    url: path,
    success: function(result) {
        $('#AjaxStudentInClassPartial').html(result);
        }
    });
return false;
}

[JQuery Plugins] JQuery Validation 在Form中如何取消某個submit button的驗證

How To disable (cancel) JQuery validation for a specify submit button in a form?
========
方法簡單明瞭,只需要:




Refrence: http://stackoverflow.com/questions/203844/jquery-validation-plugin-disable-validation-for-specified-submit-buttons

2011年4月25日 星期一

[JQuery] Jquery Ajax Post

長成這樣:

$.ajax({
                     url: '<%= Url.Content("~/OtherManager/SetTeacherUserName2/") %>',
                     data: { TeacherId: $(this).parent().attr("id"), TeacherUserName: $(this).attr("value") },
                     dataType: "text",
                     type: 'POST',
                     success: function (data) {
                         $('#ErrorMsg').text(data).css("color", "Red").fadeIn(3000, function () {
                             $('#ErrorMsg').fadeOut(3000, function () { });
                         });
                     }
                 });



其中:
url: 要post的URL路徑
data: 要傳過去URL的參數
dataType: 回傳的資料型態,常用為 text 與 json
type: 指定要POST還是GET
success: 成功之後要執行的function
Refrence: http://api.jquery.com/jQuery.ajax/   http://api.jquery.com/jQuery.post/

[JQuery] this 與 $(this) 的差別 (The different between this and $(this) in JQuery)

在JQuery中,this代表目前的DOM對象,$(this)代表我們用JQuery所選取的JQuery對象,
其實this就是最原生的javascript語法,可以把它想像成C#物件中的this就可以,
而$(this)則是使用JQuery選取元素後所代表的該元素本身的JQuery物件。看個例子就可以明白:

例如我們的HTML為:


外觀長這樣:


我們想要使用JQuery操作滑鼠移過與離開input text時顯示訊息:
1. 使用this
$("#UserName").hover(       function() {            this.value = "Hi~ you hover me";       },       fucntion() {           this.value = "Hi~ you leave me";       } );


2. 使用$(this)
$("#UserName").hover(       function() {          $(this).attr("value","Hi~ you hover me");       },       function() {          $(this).attr("value","Hi~ you leave me");       } );


---
兩者如何互相轉換?
$(this)[0] == this

例如:
$("#myDiv")[0] == document.getElementById("myDiv");
---

Refrence:

[JQuery] 如何取得父節點的id (How to get the id of parent DOM)

HTML:
< td id="1">



< /td>


JQuery:
$(".clsTeacherUserName").change(function () {
    var id = $(this).parent().attr("id");  //id = 1
});


Refrence:  http://stackoverflow.com/questions/545978/finding-the-id-of-a-parent-div-using-jquery
JQUERY-parent: http://api.jquery.com/parent/

2011年4月21日 星期四

[ASP.NET MVC] 如何在View中使用強型別DropDownListFor

How to use the strongly type "DropDownListFor" in View in ASP.NET MVC.
===============================================================
First, Assume I have two tables "Person,Weapon" both have relationship:

[Person]
{
    PersonID
    WeaponID
}

[Weapon]
{
    WeaponID
    WeaponName
}

---
OK, now I want to show the information of all the Person in database. I should write:
using (Entites db = new Entites())
            {
                var result = (from s in db.Person.Include("Weapon") select s).ToList();
                return View(result);
            }
            return View();


View:
<% foreach (var item in Model) { %>
        <%: Html.DropDownListFor(s=>s.Person.Where(a=>a.WeaponID == item.WeaponID).WeaponID , 
    new SelectList(MyApplication.Models.DropDownList.GetDropDownList(), "Value", "Text", item.WeaponID )%>    
><% } %>



Now we should write the class DropDownList with namespace MyApplication.Models:
class DropDownList
    {
        public List GetDropDownList()
        {
            List result = new List();
            result.Add(new System.Web.Mvc.SelectListItem
            {
                Value = "1",
                Text = "Apple"
            });
            result.Add(new System.Web.Mvc.SelectListItem
            {
                Value = "2",
                Text = "Milk"
            });
            return result;
        }
    }


In fact, GetDropDownList() Method can access the data via Weapon table in our database.

Reference:http://stackoverflow.com/questions/4312925/asp-net-mvc-dropdownlistfor-or-dropdownlist-with-strongly-typed-viewmodel

weak-type: http://ittecture.wordpress.com/2009/05/10/tip-of-the-day-208-asp-net-mvc-populating-dropdownlists-using-linq-to-sql/

Some discussion: http://stackoverflow.com/questions/1916462/dropdownlistfor-in-editortemplate-not-selecting-value

2011年4月20日 星期三

[Visual C#]兩個List相減

原本是想要做兩個List<string>相減,結果找到個好方法:
        public static IEnumerable Subtract(IEnumerable source, IEnumerable other)
        {
            return Subtract(source, other, EqualityComparer.Default);
        }

        public static IEnumerable Subtract(IEnumerable source, IEnumerable other, IEqualityComparer comp)
        {
            Dictionary dict = new Dictionary(comp);
            foreach(T item in source)
            {
                dict[item] = null;
            }

            foreach(T item in other)
            {
                dict.Remove(item);
            }

            return dict.Keys;
        }

參考資料:
http://stackoverflow.com/questions/2266682/how-to-substract-one-generic-list-from-another-in-c2-0

備註:C#預設交集操作:
http://msdn.microsoft.com/zh-tw/library/bb460136.aspx

[Plugins] SyntaxHighlighter 部落格貼程式碼的好幫手

官方網站:

SyntaxHighlighter 3.0.83


先在部落格引用下列檔案

使用方式:
1
2
3
4
5
6
7
8
9
10
11
<pre class="brush: js">
    /**
     * SyntaxHighlighter
     */
    function foo()
    {
        if (counter <= 10)
            return;
        // it works!
    }
</pre>



支援的程式語言:
http://alexgorbatchev.com/SyntaxHighlighter/manual/brushes/

列表:

Brush nameBrush aliasesFile name
ActionScript3as3, actionscript3shBrushAS3.js
Bash/shellbash, shellshBrushBash.js
ColdFusioncf, coldfusionshBrushColdFusion.js
C#c-sharp, csharpshBrushCSharp.js
C++cpp, cshBrushCpp.js
CSScssshBrushCss.js
Delphidelphi, pas, pascalshBrushDelphi.js
Diffdiff, patchshBrushDiff.js
Erlangerl, erlangshBrushErlang.js
GroovygroovyshBrushGroovy.js
JavaScriptjs, jscript, javascriptshBrushJScript.js
JavajavashBrushJava.js
JavaFXjfx, javafxshBrushJavaFX.js
Perlperl, plshBrushPerl.js
PHPphpshBrushPhp.js
Plain Textplain, textshBrushPlain.js
PowerShellps, powershellshBrushPowerShell.js
Pythonpy, pythonshBrushPython.js
Rubyrails, ror, rubyshBrushRuby.js
ScalascalashBrushScala.js
SQLsqlshBrushSql.js
Visual Basicvb, vbnetshBrushVb.js
XMLxml, xhtml, xslt, html, xhtmlshBrushXml.js