So, I have been building an ASP.NET MVC 5 web application making use of the Azure.Mobile.Server SDK. So I created my model objects, and everything is excellent. I used the scaffolding to generate my Controllers and Views. From there I spent some time customizing my views, which I hate to do. I’m not a very good front-end developer, and I have all the respect in the world for those who are skilled at making things look pretty. So I went to test the various CRUD operations and starting at Create, I failed. I set a breakpoint and found out that my model state was invalid. The default code does something like this:
When I was clicking the submit button on my form, the check of ModelState.IsValid was coming back false. This is because in my form, I was only adding data to “ModelProperty.” The rest of the bindings (Id, Version, CreatedAt, UpdatedAt, Deleted) are all part of the Microsoft.Azure.Mobile.Server.EntityData object type which I inherited in my model. I use this data type because I have an accompanying mobile app and the Mobile SDK does a great job of offline syncing my data. So… I had to remove those bindings from the [Bind(Include = “…”)] statement. Once I removed those, my ModelState was valid, and life continued.