I have a customized ModelBinder whi开发者_如何学运维ch bind web from with a object using code like this"
[ModelBinder(typeof(CustomizedModelBinder))]
public class Widget{ ... }
This modelbinder may throw exceptions and where should I add code to catch those exceptions? Thanks in advance!
From design perspective it is better for a model binder to add model errors instead of throwing exceptions:
ModelState.AddModelError("Phone", "Phone number is invalid.");
This way, later in your action you could check if the model is valid:
if (!ModelState.IsValid)
{
...
}
精彩评论