• ASP.NETMVC3RC的一些新特性 (2010.11.9发布版)


    1控制Controller的SESSION

     [ControllerSessionState(SessionStateBehavior.Disabled)]

    //禁用SESSION

    public class CoolController : Controller {

      public ActionResult Index() {

    object o = Session["Key"]; // 触发异常

      }

    }

     [ControllerSessionState(SessionStateBehavior.ReadOnly)]

    public class CoolController : Controller {

      public ActionResult Index() {

    Session["Key"] = "value"; // SESSION属于只读

      }

    }

    2新的验证属性

    2.1比较Compare

    public class User {

        [Required]

        public string Password { get; set; }

        [Required, Compare("Password")]

        public string ComparePassword { get; set; }

    }

    2.2 控制客户端属性

    UserName 属性被赋予UserNameAvailable,当username属于被编辑页面的时候,客户端验证将调用UserNameAvailable 方法

    public class User {

        [Remote("UserNameAvailable", "Users")]

        public string UserName { get; set; }

    }

    The following example shows the corresponding controller.

    public class UsersController {

        public bool UserNameAvailable(string username) {

            return !MyRepository.UserNameExists(username);

        }

    }

    2.3LabelFor和LabelForModel的新的重载函数

     @Html.LabelFor(m => m.PropertyName, "Label Text");

    @Html.LabelForModel("Label Text");

    3action可以使用缓存

    当前时间: @DateTime.Now

    被缓存时候的事件: @Html.Action("GetDate")

    The GetDate action is annotated with the OutputCacheAttribute:

    [OutputCache(Duration = 100, VaryByParam = "none")]

    public string GetDate() {

        return DateTime.Now.ToString();

    }

    4"Add View" 的对话框变干净了。

    不会跟以前一样把整个.NET FRAMEWORK 的类 都包含进去。

    5 更小粒度的验证Granular Request Validation

    跳过验证。

    这次是粒度到了某个属性

    public class BlogPostViewModel {  

        [SkipRequestValidation]

        public string Description {get; set;}

    }

    之前的版本的粒度是整个函数

    [HttpPost]

    [ValidateInput(false)]

    public ActionResult Edit(BlogPostViewModel post) {

        // Save the post in the database

  • 相关阅读:
    Integer判等的陷阱:你知道Integer内部高速缓冲区IntegerCache吗?
    Unicode 是不是只有两个字节,为什么能表示超过 65536 个字符
    java中Char到底是什么格式的编码
    Java中char和String 的深入理解
    关于serialVersionUID的说明
    Java中的instanceof和isInstance基础讲解
    编码(1)学点编码知识又不会死:Unicode的流言终结者和编码大揭秘
    知识图谱和图卷积(贪心学院)——学习笔记
    索尼相机,索尼W35,Sony Cyber-shot DSC-w35
    高斯分布与高斯过程梳理
  • 原文地址:https://www.cnblogs.com/facingwaller/p/MVC3RC_New_Features.html
Copyright © 2020-2023  润新知