What do I do if the input does not qualify to the object model I'm trying to bind to?
for instance, a person has a FirstName
and a LastName
, so it might have a model binder like:
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
var querystrings = controllerContext.HttpContext.Request.QueryString;
Dictionary<string, string> queryParams = querystrings.Cast<string>()
.Select(s => new { Key = s, Value = querystrings[s] })
.ToDictionary(p => p.Key, p => p.Value);
return new Person
{
FirstName = queryParams["firstName"],
LastName = queryParams["lastName"]
};
}
But what if firstName
or lastName
are not present? how do I signal that i failed to bind?