0

I want to implement a model validation logic on a model entity that contains a model property of string type which represents other property's data type (e.g. Boolean, float, integer, datetime, string).

I want to find out the options available, or potentially the best option.

Below is the model entity:

public class CarEditViewModel
   {
        public List<CarParameter> CarParameters {get;set;}
        //other properties
   }

public class CarParameter
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
    public virtual bool ShowHide { get; set; }
    public virtual string DefaultValue { get; set; }
    public virtual string DataType { get; set; }  //can be type of Boolean, float, integer, datetime, string
}

As shown above, the DataType represents the data type of DefaultValue property. The CarEditViewModel is used on MVC edit view. CarEditViewModel contains a collection of CarParameter.

Thanks!

Pingpong
  • 7,681
  • 21
  • 83
  • 209

1 Answers1

1

A better approach would be to create that as an enum.

If you are using MVC 3, checkout IValidatableObject.

How do I use IValidatableObject?

Community
  • 1
  • 1
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445