zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    [转]HSPICE软件的应用及常见问题解决
    Node.js基于Express框架搭建一个简单的注册登录Web功能
    Node.js开发Web后台服务
    mysql update 将一个表某字段设为另一个表某字段的值
    一个最简的Thinkphp3.2 操作Mongodb的例子
    MongoDB GUI( Robo 3T) Shell使用及操作
    Robomongo,Mongo可视化工具
    thinkphp mysql和mongodb 完美使用
    大型网站系统架构演化之路
    30个php操作redis常用方法代码例子
  • 原文地址:https://www.cnblogs.com/facingwaller/p/MVC3RC_New_Features.html
Copyright © 2011-2022 走看看