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.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.