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.
- name
- description (optional)
a "file" has:
- list item
- filepath
an announcement has:
- priority
- 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
Post a Comment