asp.net mvc的automapper解析 [英] asp.net mvc automapper parsing

查看:259
本文介绍了asp.net mvc的automapper解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们有这样的事情

public class Person
{
   public string Name {get; set;}
   public Country Country {get; set;}
}

public class PersonViewModel
{
   public Person Person {get; set;}
   public SelectList Countries {get; set;}
}

可以automapper用于执行从人到解析为PersonViewModel和后面?

can automapper be used to perform to parse from Person into PersonViewModel and back ?

推荐答案

不要使用AutoMapper这 - 这不值得。例如,在你有一个验证失败,并再次显示窗体的情况下 - 这里不(通常)执行AutoMapper。我们通常会去两条路线:

Don't use AutoMapper for this - it's not worth it. For example, in the cases where you have a validation failure and you show the form again - AutoMapper is not executed here (usually). We usually go two routes:


  • 如果该列表是不特定的上下文,创建查询一些ISelectListProvider的选择列表项的的HtmlHelper:Html.DropDownList()。你会用你的IoC容器选择来定位personListProvider,查询项目列表,并填充下拉列表。

  • 如果该列表是上下文相关的,只是做成了控制器动作列表

这篇关于asp.net mvc的automapper解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆