English 中文(简体)
我可以使用数据说明 与 View model 课程?
原标题:Can I use DataAnnotations with Viewmodel classes?

在我的解决办法中,我有一个ASP.NET MVC3项目和一个与数据库合作的周转基金项目。我将使用 < code> Automapper 来绘制物体。

我的问题是:我能否在我的观景模型课程中使用数据说明, 并把它们映射到从周转基金服务项目收到的物体上?

类似

public class User
{
    [Required,MaxLength(30)]
    public string UserName { get; set; }

    [Required]
    public string Email { get; set; }
}
最佳回答

我用它们做两件事:

  • Entity Framework mappings to tell Entity Framework how to generate a column (although I usually use the fluent API for this)
  • Input validation, so this is where your ViewModel comes in. You can annotate it with the dataannotations, and use jquery.validate and MVC s ModelState.IsValid to verify that all requirements were met.

当一切正常时, 您可以将视图模式映射为 POCO/ 实体, 没有附加说明 。

问题回答

暂无回答




相关问题
WCF DataMember Serializing questions

Ok, so I was part way through the long winded process of creating DTOs for sending my model over the wire and I don t feel like I m going down the right route. My issue is that most of the entities ...

Access WCF service on same server

I have a .NET website with a WCF service. How do I access the current operations context of my service? One possible work around is to just make a call to the service within the app...but that seems ...

WCF binding error

So I got into work early today and got the latest from source control. When I try to launch our ASP.NET application, I get this exception: "The binding at system.serviceModel/bindings/wsHttpBinding ...

The service operation requires a transaction to be flowed

I am facing strange issue with our WCF service. The same code was working fine until recently we added more OperationContracts(Web Methods). We have common 3 tier architecture. DAL (WCF) BLL Web ...

热门标签