ASP.Net MVC varying required fields -


i have single form used create similar items. simplify scenario demonstration.

you can create 1 of many "content types". can choose add "file", "folder", "announcement", etc. use /home/addcontent?contenttype=file determine options show in view.

each content item has following.

  1. name
  2. description (optional)

a "file" has:

  1. list item
  2. filepath

an announcement has:

  1. priority
  2. displayhomepageflg (optional)

i add of these 1 viewmodel of data annotations modelstate.isvalid never true since each "content type" has unique properties.

is there programatic way add or exclude specific data annotations or should have separate viewmodel , controller each content type?

the way can think of use remotevalidationattribute.

look here sample

then in controller, not use modelstate.isvalid, validation in business logic layer

you can think of using jquery.validation own scripts check fields


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -