Translate

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

2013年9月9日 星期一

Iframe使用TempData消失

遇到一個很奇怪的問題
每次存完MVC TempData後,接下來要用就找不到了
(當用IFrame使用MVC頁面時)
後來發現只有IE才會發生,解決方法如下

 //因為IFrame,IE會無法存取Session,故加上此
 Response.AddHeader("P3P", "CP=\"CAO PSA OUR\"");
TempData["username"] = username;


參考網址ref→http://renjin.blogspot.tw/2008/02/p3p.html

2013年5月31日 星期五

Binding TextBox Null Value

當你的資料庫欄位給予你的string→其實一開始就是null

這時後當你更新之後,你會發現總是跳出錯誤訊息,解決方法如下

note這個字串一開始初始化是null

  <asp:TextBox ID="txtinput" runat="server"  Text='<%# Bind("note") %>' ></asp:TextBox>

解法方法:只要判定為舊值為null時給予空白字串即可更新
        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            if (e.OldValues["note"] == null) e.OldValues["note"] = "";
        }


參考連結:

Binding a nullable int to an TextBox

2012年10月19日 星期五

EntityDataSource Where查詢

當有使用EntityDataSource進行查詢時
只需要在EntityDataSource_ContextCreated(object sender, EntityDataSourceContextCreatedEventArgs e)
內重新改寫

 EntityDataSourceCom.Where 即可


比較注意的重點

一、當查詢的為時間建議寫:

it.Time>=DATETIME'" + DateTime.Now.ToString("yyyy-MM-dd HH:mm") + "'"

二、當有AND跟OR要連結起來時寫法(這個倒是試了一陣子)


 EntityDataSource.Where= "it.name='%台灣%' AND (it.bookname='%自然%' OR it.bookname='%數學%')"

試過不可行的方式…
 EntityDataSource.Where= " (it.bookname='%自然%' OR it.bookname='%數學%') AND it.name='%台灣%'"

ref→http://huan-lin.blogspot.com/2011/04/entitydatasourceselect-it.html:說明it是什麼

2012年7月30日 星期一

MVC Razor

ref→http://weblogs.asp.net/scottgu/archive/2010/12/15/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax.aspx

先記一下,MVC相關語法

若要從routerView取得id資料
@ViewContext.RouteData.Values["Id"]

若要從Cotroller取得id資料
this.RouteData.GetRequiredString("id")

祝學習愉快

2012年3月30日 星期五

aspx頁面上使用資源字串

當要在aspx頁面上使用資源字串的方法

通常是用在不需要放在控制項目內的字串


<%=Resources.資源檔名.key值%>




通常是放在控制元件的寫法…

 <asp:ListItem Value="1" Text="<%$ Resources: 資源檔名 ,  key值 %>"/>