Yes and no. Modelbinding validation only takes you so far. If you have dynamic rules then model based validation falls apart.
I do use the validation attributes on the entity model, but only for basic stuff like empty values, ranges etc.. Ultimately, I want validation logic in my business object that can check it all. My business layer looks at validation errors that are internally assigned (via an OnValidate() method that allow for easy coded rules) or those that are fired via validation errors on the entity model when the model is saved by EF, so it works either way.
Modelbinding by itself is not enough IMHO...
+++ Rick ---
>Looks like you're rolling your own validation and display rather than using the standard ModelState.IsValid and ModelState.AddModelError(). Am I correct in this? If so, why did you roll your own?
>
>
>>You should use ModelBinding. Modelbinding maps fields of the form to an object with properties of the same name. Typically a view model is used rather than the entity so you can pass multiple pieces of information to the view - like error information or other messages that need to display in the UI.
>>
>>Here's an example of a model passed to save into an entity (using a bus object, but the same would roughly work with your EF repository):
>>
>>
>> [HttpPost]
>> public ActionResult Save(EntryViewModel model)
>> {
>> if (!ModelState.IsValid)
>> {
>> // Handle error and display error result
>> model.ErrorDisplay.ShowError(model.ErrorDisplay.AddMessages(ModelState))
>> return View("Show");
>> }
>>
>> var entryBus = new busEntry();
>>
>> // get entity that needs to be updated
>> var entry = entryBus.Entity;
>> entry.Id = model.entry.Id;
>> entry.Title = model.entry.Title;
>> entry.Description = model.entry.Description;
>> // ... more fields to map
>>
>> // Or you can attach the entity - in my bus object
>> // this is automatic, with EF you can use DbSet::Attach
>> //entryBus.Attach(model.entry);
>>
>> // Validate and save the bus object
>> if (!entryBus.Validate() || !entryBus.Save())
>> {
>> model.ErrorDisplay.ShowError(model.ErrorDisplay.AddMessages(entryBus.ValidationErrors));
>> return View("Show");
>> }
>>
>> // Saved and done
>> return View("Index");
>> }
>>
>>
>>Hope this helps,
>>
>>+++ Rick ---
>>