1

I have a single form used to create similar items. I will simplify the scenario for demonstration.

You can create one of many "Content Types". You can choose to add a "File", "Folder", "Announcement", etc. I would use /home/addcontent?contenttype=FILE to determine what options to show in the view.

Each content item has the following.

  1. Name
  2. Description (optional)

A "File" also has:

  1. List item
  2. FilePath

An Announcement also has:

  1. Priority
  2. DisplayHomepageFLG (optional)

I could add all of these to one viewmodel with all of the data annotations but modelstate.isvalid would almost never be true since each "content type" has unique properties.

Is there some programatic way to add or exclude specific data annotations or should I have a separate viewmodel and controller for each content type?

ericdc
  • 11,217
  • 4
  • 26
  • 34

1 Answers1

0

The only way I can think of is to use RemoteValidationAttribute.

Look here also for a sample

Then in your controller, you will not use ModelState.IsValid, but only the validation in your business logic layer

You can also think of using JQuery.validation with your own scripts to check the fields

Iridio
  • 9,213
  • 4
  • 49
  • 71