ViewModel就是一个实体类,定义上跟Model没有任何区别.只是在设计和使用时要依赖页面
新建一个类,按照ViewModel的写法去写,不就ok了?
基本上是按照DB中的字段去写,ViewModel就是对应View中的数据:
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.ComponentModel.DataAnnotations; using HTCSystem.Data.Translations; namespace HTC_Development_Template1Portal.ViewModels { public class StoreModelView { [Display(Name = "StoreID")] public int StoreId { get; set; } [Display(Name = "StoreName", ResourceType = typeof(UserInterfaceResx))] public string StoreName { get; set; } [Display(Name = "Country", ResourceType = typeof(UserInterfaceResx))] public string CountryDigit2 { get; set; } [Display(Name = "Area", ResourceType = typeof(UserInterfaceResx))] public int AreaId { get; set; } [Display(Name = "State", ResourceType = typeof(UserInterfaceResx))] public int ProvinceId { get; set; } [Display(Name = "City", ResourceType = typeof(UserInterfaceResx))] public int CityId { get; set; } [Display(Name = "Tel", ResourceType = typeof(UserInterfaceResx))] public string Tel { get; set; } [Display(Name = "Fax", ResourceType = typeof(UserInterfaceResx))] public string Fax { get; set; } [Display(Name = "Phone", ResourceType = typeof(UserInterfaceResx))] public string Phone { get; set; } [Display(Name = "Contact", ResourceType = typeof(UserInterfaceResx))] public string Contact { get; set; } [Display(Name = "Email", ResourceType = typeof(UserInterfaceResx))] public string Email { get; set; } [Display(Name = "Address", ResourceType = typeof(UserInterfaceResx))] public string Address { get; set; } [Display(Name = "StoreGroup", ResourceType = typeof(UserInterfaceResx))] public int StoreGroupId { get; set; } [Display(Name = "HTCSales", ResourceType = typeof(UserInterfaceResx))] public int? SalesId { get; set; } [Display(Name = "KeyWord", ResourceType = typeof(UserInterfaceResx))] public string KeyWord { get; set; } [Display(Name = "BusinessCircle", ResourceType = typeof(UserInterfaceResx))] public string BusinessCircle { get; set; } [Display(Name = "HTCAmbassador", ResourceType = typeof(UserInterfaceResx))] public int? HTCAmbassadorId { get; set; } [Display(Name = "StoreLevel", ResourceType = typeof(UserInterfaceResx))] public string StoreLevel { get; set; } } }
View中 调用对应的ViewModel:
@model 项目名称.ViewModels.StoreModelView