zoukankan      html  css  js  c++  java
  • asp.net MVC 笔记

    ---------------------------------------------------------------------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" />

  • 相关阅读:
    批量改文件名小工具
    整理一下在 npmjs.com 上面发布资源包踩过的坑
    告别Vuex,发挥compositionAPI的优势,打造Vue3专用的轻量级状态
    vue3 专用 indexedDB 封装库,基于Promise告别回调地狱
    C++ 学习笔记(三):介绍几个在线编译器【转】
    【Linux】一篇文章彻底搞定信号!【转】
    缓存淘汰算法系列(一)【转】
    缓存淘汰算法 LRU 和 LFU【转】
    NAND Flash标准之ONFI VS TOGGLE【转】
    NAND FLASH学习笔记之nand flash基础(一)【转】
  • 原文地址:https://www.cnblogs.com/iceberg2008/p/4032780.html
Copyright © 2011-2022 走看看