0

Method Signature looks like this

public async Task<IHttpActionResult> CreateAccountAsync(UserModel user,
        string email,
        string password,
        string role = "",
        string phoneNumber = "")

When the request comes; ModelState is always invalid and always complaining about email, password, role and phoneNumber

Initial Model State

All the parameters are Invalid according to Model State

Email has value

As you can see in the image above; email has value and it still complains about it..

user1932923
  • 354
  • 3
  • 18
  • Are you sure it is complaining about email etc. In your screenshots, these are the keys inside the ModelState, i.e. what values are contained inside it, not the fields which validation errors. Also you can see in the last screen that `Errors = 0` for email, suggesting it is valid. Do you have an `email` property in your `UserModel`? It may be that the value is being used for the raw parameter rather than the user property value or you just aren't setting it – Rhumborl Apr 01 '16 at 20:04
  • Sorry, my bad. It seems it's not liking the phoneNumber = "", as we don't pass any value. Is there a way to pass null or empty and have ModelState not care about it? – user1932923 Apr 01 '16 at 20:10
  • It is just part of the method signature. Is there a way to explicitly state required or not? – user1932923 Apr 01 '16 at 20:16
  • 1
    You might need a custom binder then - have a look at http://stackoverflow.com/questions/32861365/modelstate-isvalid-is-false-when-i-have-a-nullable-parameter – Rhumborl Apr 01 '16 at 20:19
  • That seems to be the solution. Thank You. Can you please put the link as an answer and I will mark it as an answer to this questions... – user1932923 Apr 01 '16 at 20:44

0 Answers0