在create页面中,所有jquery验证都通过,当create对象被传递到操作时,UpdateModel失败。无论如何,我是否可以找到哪个字段显式地失败了更新?通过在调试模式下看"e“?
try {
UpdateModel(house_info); }
catch (Exception e)
{ throw e; } 发布于 2014-09-15 07:47:58
您可以检查ModelState是否有错误。下面将给出每个有错误的属性的列表,以及与该属性关联的第一个错误
var errors = ModelState.Keys.Where(k => ModelState[k].Errors.Count > 0)
.Select(k => new
{
propertyName = k,
errorMessage = ModelState[k].Errors[0].ErrorMessage
});发布于 2014-09-15 07:57:00
此外,ModelState有一个.IsValid属性,您可能应该检查该属性,而不是使用异常处理。
控制器操作可能看起来像:
public void MyAction() {
if(ModelState.IsValid) {
// do things
}
// error handling, perhaps look over the ModelState Errors collection
// or return the same view with the 'Model' as a parameter so that the unobtrusive javascript
// validation would show the errors on a form
}https://stackoverflow.com/questions/25842873
复制相似问题