【问题标题】:Validation of String ViewModel字符串 ViewModel 的验证
【发布时间】:2011-05-13 23:24:24
【问题描述】:

我在某处读到视图模型属性只能是字符串。 例如

class PersonViewModel
{
   public string Number {get;set;}
   public string FullName {get;set;}
   public string Birthday {get;set;}
}

如何像使用 ValidationAttributes 一样轻松地验证此模型 和“正常”模型中的 ModelState.IsValid 方法?

统一更新: 我使用 AutoMapper 将 ViewModel 映射到此域模型:

class Person
{
   public int ID {get;set;}
   public string FullName {get;set;}
   public DateTime Birthday {get;set;}
}

【问题讨论】:

    标签: asp.net asp.net-mvc-2 validation


    【解决方案1】:

    不,那不是真的。通过模型绑定,MVC 会处理它。

    这是一个教程。

    http://www.asp.net/mvc/tutorials/validation-with-the-data-annotation-validators-cs

    【讨论】:

      猜你喜欢
      • 2011-02-21
      • 1970-01-01
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多