我有一个客户端类,我需要将它映射到一个不太复杂的clientViewModel类,下面是两个类:
public class client
{
public int clientRef{get;set;}
public string Title{get;set;}
public string Forename { get; set; }
public string Initials { get; set; }
public string Surname { get; set; }
Public Address address{get;set;}
}和
public class ClientsViewModel
{
public int ClientRef { get; set; }
public string Title { get; set; }
public string Forename { get; set; }
public string Initials { get; set; }
public string Surname { get; set; }
public string Line1 { get; set; }
public string Line2 { get; set; }
public string Line3 { get; set; }
public string Town { get; set; }
public string County { get; set; }
public string Postcode { get; set; }
public string Country { get; set; }
}这就是我映射模型的方式(它仍然是一个概念的证明)
IList<ClientsViewModel> _clientsViewModelsclients = new List<ClientsViewModel>();
var model =
new Clients().Get(10);
Mapper.CreateMap<Client, ClientsViewModel>();
ClientsViewModel cv = Mapper.Map<Client, ClientsViewModel>(model);
_clientsViewModelsclients.Add(cv);
return View(_clientsViewModelsclients);问题出在视图上,我可以看到名称和标题,但看不到地址。还有没有我应该做的其他映射?不要确保address行1中的内容映射到clientViewModel类的Line1?
谢谢
发布于 2013-02-05 19:35:43
来自评论
在这里看一下:或者你可以创建一个自定义的解析器..
https://stackoverflow.com/questions/14688650
复制相似问题