I am using the first ASP.NET MVC 3 code, and I have added validation data annotations for my models. Here is an example model:
public class Product { public int ProductId { get; set; } [Required(ErrorMessage = "Please enter a name")] public string Name { get; set; } [Required(ErrorMessage = "Please enter a description")] [DataType(DataType.MultilineText)] public string Description { get; set; } [Required(ErrorMessage = "Please provide a logo")] public string Logo { get; set; } }
On my website I have a multi-step process of creating a new product - step 1 you enter the product information, step 2 - other information, etc. Between each step, I store each object (i.e. the Product object) in the session, so the user can return to this stage of the process and change the entered data.
On each screen, I have client side validation working with the new jQuery validation.
The final stage is the confirmation screen, after which the product is created in the database. However, since the user can jump between stages, I need to check the objects (Product and some others) to make sure that they performed the data correctly.
Is there a way to programmatically call a ModelState check on an object with data annotations? I do not want to go through each property of the object and perform a manual check.
I am open to suggestions on how to improve this process if it simplifies the use of the ASP.NET MVC 3 model validation functions.
Sam Huggill Jun 15 2018-11-15T00: 00Z
source share