Use .NET MVC and Code EF to implement the requested functionality. Business objects are relatively complex, and I use System.ComponentModel.DataAnnotations.IValidatableObjectto validate a business object.
Now I'm trying to find a way to show the result of validation from a business object using MVC ValidationSummary without using data annotations. For example (very simplified):
Business Object:
public class MyBusinessObject : BaseEntity, IValidatableObject
{
public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
{
return Validate();
}
public IEnumerable<ValidationResult> Validate()
{
List<ValidationResult> results = new List<ValidationResult>();
if (DealType == DealTypes.NotSet)
{
results.Add(new ValidationResult("BO.DealType.NotSet", new[] { "DealType" }));
}
return results.Count > 0 ? results.AsEnumerable() : null;
}
}
Now in my MVC controller I have something like this:
public class MyController : Controller
{
[HttpPost]
public ActionResult New(MyModel myModel)
{
MyBusinessObject bo = GetBoFromModel(myModel);
IEnumerable<ValidationResult> result = bo.Validate();
if(result == null)
{
}
return View(myModel);
}
}
In mind, I have Html.ValidationSummary();.
How can I pass IEnumerable<ValidationResult>to ValidationSummary?
I tried to find the answer on googling, but all the examples that I found describe how to show a validation summary using data annotations in the model, and not in the business object.
thank