标签: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" />
标签:http io os ar java for sp 数据 2014
原文地址:http://www.cnblogs.com/iceberg2008/p/4032780.html