If you haven't already, read the first two parts in this series on Model Binding, which covers the basics of selecting data via the new Select Method property on data-controls like the Grid View, as well as filtering that data based on input from the user.
In today's post we'll look at how Model Binding improves the data-binding experience when updating data.
It takes advantage of a bunch of model binding concepts we first introduced with ASP.
NET MVC - and integrates them nicely with the Web Forms server control model.
Let's change our update method to use this approach: This time, the Web Forms Model Binding system will populate the product Id parameter from the data-controls Data Keys collection (it does this implicitly; no value provider attributes are required).
We then retrieve the product from the database, and call Try Update Model to model bind the values from the data-control onto the object.
We can then explicitly inspect the property to ensure the model state is valid before saving changes: Now, if we try to update a record with an invalid value, the Grid View will stay in edit mode and the model state error message will be displayed by the Validation Summary: You can also add custom or ad-hoc error messages to the page's model state, to represent other error conditions not covered by the validation attributes. NET MVC Controllers, the Web Forms Page base class now has a "Model State" property that you can use to populate custom error messages that validation controls within the page can access and use to display any error message you want. NET Web Forms 4.5 makes it easy to work with data and user input using a code-focused data-access paradigm.
Using Visual Studio 2010, I created a BDC Model and deployed it to a Share Point 2010 farm.
NET MVC, and supports a consistent way to use Data Annotation attributes across both MVC and Web Forms to apply validation behavior to model objects.
All the techniques shown here can be equally applied to the other data-controls in ASP.
Once that's done, we save the changes to the database.
Of course, most data models include some type of validation rules. NET Dynamic Data, MVC, Entity Framework and Silverlight RIA Services does.