Saturday, August 4, 2012

errors.add for ASP.NET MVC

In Ruby on Rails, we should add error information of model with errors.add method from ActiveModel::Errors class.
  errors.add(:customer, 'Invalid country.')

I learned from the book Programming Microsoft® ASP.NET MVC, Second Edition that we should add error information of model with ViewData.ModelState.AddModelError method from System.Web.Mvc.ModelStateDictionary class.
    ViewData.ModelState.AddModelError("Customer", "Invalid country.");

No comments:

Post a Comment