找到的UpdateModel失败原因 [英] find UpdateModel Fail Reason

查看:468
本文介绍了找到的UpdateModel失败原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个创建视图页面,所有的jQuery验证通,当创建对象得到传递到动作,的UpdateModel失败。反正是有,我可以找到哪些领域明确失败的更新?通过在调试模式看E?

  {尝试
      的UpdateModel(house_info); }
 赶上(例外五)
     {抛出ê; }


解决方案

您可以检查的ModelState 错误。下面将给你一个与物业相关的错误,第一个错误的每个属性的列表

  VAR误差= ModelState.Keys.Where(K =>的ModelState [K] .Errors.Count大于0)
  。选择(K =>新建
  {
    propertyName的= K,
    的errorMessage =的ModelState [k]的.Errors [0] .ErrorMessage
  });

In a create view page, all jquery validation pass, when the create object got passed into action, the UpdateModel fails. Is there anyway that I can find which field explicitly fail the update? By watching "e" in Debug Mode?

 try { 
      UpdateModel(house_info); }
 catch (Exception e) 
     { throw e; } 

解决方案

You can inspect ModelState for errors. The following will give you the list of each property that has an error and the first error associated with the property

var errors = ModelState.Keys.Where(k => ModelState[k].Errors.Count > 0)
  .Select(k => new
  {
    propertyName = k,
    errorMessage = ModelState[k].Errors[0].ErrorMessage
  });

这篇关于找到的UpdateModel失败原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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