我是ASP.NET MVC的新手.我在理解ViewModel的目的时遇到了问题.
什么是ViewModel,为什么我们需要一个用于ASP.NET MVC应用程序的ViewModel?
如果我能有一个简单的例子,那就更好了.
我有实体框架生成的以下类:
public partial class ItemRequest
{
public int RequestId { get; set; }
//...
Run Code Online (Sandbox Code Playgroud)
我想把它变成一个必填字段
[Required]
public int RequestId { get;set; }
Run Code Online (Sandbox Code Playgroud)
但是,因为这是生成的代码,这将被消灭.我无法想象一种创建分部类的方法,因为属性是由生成的分部类定义的.如何以安全的方式定义约束?
如果我使用Entity Framework(v5.0)数据库第一种方法,那么使用数据注释进行验证的最佳方法是什么?
这是我的Entity Framework创建的部分类:
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated from a template.
//
// Manual changes to this file may cause unexpected behavior in your application.
// Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System.ComponentModel.DataAnnotations;
namespace ACore
{
using System;
using System.Collections.Generic;
public partial class PayrollMarkup_State
{
[UIHint("StatesEditor")] // <-- I added this line but it will be overwritten
public string State { get; set; }
public …Run Code Online (Sandbox Code Playgroud)