处理Automapper例外? [英] Handle Automapper exception?

查看:186
本文介绍了处理Automapper例外?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用mvc5与automapper我有以下几点:

Using mvc5 with automapper I have following:

在控制器:

  [HttpPost]
        public ActionResult LunchMenu_Create_Index(VmSysMenuCreate menu)
        {
            try
            {
                var domainMenu = Mapper.Map<VmSysMenuCreate, Menu>(menu);
            }

            catch (Exception ex)
            {
                return Content("Error msg");
            }

            return Content("Succes");
        }

映射:

  Mapper.CreateMap<VmSysMenuCreate, Menu>()
                .ForMember(c => c.Id, op => op.MapFrom(v => v.Id))
                .ForMember(c => c.MenuDate, op => op.ResolveUsing(data =>
                {
                    try
                    {
                        DateTime convertedDate = Convert.ToDateTime(data);
                        return convertedDate;
                    }
                    catch (Exception ex)
                    {

                        throw new Exception("Date not in correct format", ex);
                    }

                }));

这样做,我excpected tryng映射我的对象时赶上automapper错误,但是这
工作不喜欢我期望的那样。

Doing this I was excpected to catch automapper error when tryng to map my objects , but this is not working like I was expect.

我怎么能赶上错误在从automapper抛出控制器?
如果您有任何疑问请咨询我..
感谢您的关注!

How can I catch error in controller that is thrown from automapper? If you have any question please ask me.. Thanks for you attention!

推荐答案

不知道,但也许你可以选择CLR抛出异常ON。

Not sure, but probably you have the option CLR Exceptions Thrown ON.

从调试菜单中选择例外...。 (或preSS <大骨节病> CTRL + <大骨节病> ALT + <大骨节病>电子

Select "Exceptions..." from "Debug" menu. (or press CTRL + ALT + E)

如果高亮显示抛出该异常选项,你会看到调试器在最里面的异常停止。

If the highlighted Thrown option is ON, you'll see the debugger stopping in the innermost exception.

这篇关于处理Automapper例外?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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