asp.net MVC 筆記

來源:互聯網
上載者:User

標籤:http   io   os   ar   java   for   sp   資料   2014   

---------------------------------------------------------------------15:28 2014/7/21
強型別化
後台
ViewData.Model=userInfo;//userInfo對象傳進去。
前台
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcUserDemo.Models.UserInfo>"%>
<%: Html.TextBoxFor(u=>u.UserName)%>


編碼化
<%= ViewData["strScript"]%> //不編碼
<%: Html.Raw("<p>我是HtmlRaw</p>")%> //不編碼
<%: new HtmlString("<p>不編碼</p>")%> //不編碼
<%: new MvcHtmlString("<p>不編碼</p>")%> //不編碼
<%: ViewData["strScript"]%> //編碼
<%: Html.EnCode(ViewData["strScript"])%> //編碼


擴充方法
擴充方法三個要素:靜態類,靜態方法,this關鍵字
namespace System.Web.Mvc
public static class MyHtmlHelperExt
{
public static string MyLabel(this HtmlHelper helper,string txt)
{
return string.Format("<span>{0}</span>",txt);
}
public static HtmlString MyHtmlStringLabel(this HtmlHelper helper,string txt)
{
return new HtmlString( string.Format("<span>{0}</span>",txt));
}

}


jquery確認提示
$(function(){
$("a:contains(‘刪除‘)").click(function(){
return confirm("請確認是否真的刪除資料?");
});
})

 

Razor引擎的轉換資料類型
AsInt(),IsInt(),AsFloat(),IsFloat(),AsDecimal(),IsDecimal(),AsDateTime(),IsDateTime(),AsBool(),IsBool(),ToString()

ActionResult衍生類別


路由調試設定代碼
Application_Start()
RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);

------------------------------------------------------------------------------10:39 2014/7/22--------
MVC驗證
System.ComponentModel.DataAnnotations中的ValidationAttribute基類,定義完全定製的特性
[Required][StringLength][Range][RegularExpression]
伺服器端Action中校正,Model.IsValidate為true即可。
用戶端引入jq校正<% Html.EnableClientValidation();%>
Webconfig中可以設定全域用戶端校正是否開啟或關閉。
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>


微軟提供了預設的過濾器
Authorization filter,Action filter,Result filter,Exception filter


關閉xss
<httpRuntime requestValidationMode="2.0" />

asp.net MVC 筆記

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.