开发者

asp.net mvc: TryUpdateModel return value or ModelState.IsValid?

Doing validation in my binder, I'm wondering if there's a need to check the return value. In Option 1 below, is there ever going to be a difference in case 1 and case 2? It doesn't se开发者_开发技巧em possible that TryUpdateModel would return true, but ModelState.IsValid is false.

Option 1:

  if (TryUpdateModel(editItem, new string[] { "Field" }))
  {
    if (ModelState.IsValid)
    {
    } else {
    // Invalid model case 1
  }
  } else {
    // Invalid model case 2
  }

Option 2:

  TryUpdateModel(editItem, new string[] { "Field" }))
  if (ModelState.IsValid)
  {
  } else {
    // only one invalid model case 
  }


The last line of the TryUpdateModel source code is:

        return ModelState.IsValid;

...which pretty much answers your question. :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜