Conditional data annotation

后端 未结 3 553
刺人心
刺人心 2021-02-04 02:08

Is there a way to make a data annotation conditional? I have a table Party where I store both organisations and persons. If I\'m adding an organisation I don\'t w

3条回答
  •  佛祖请我去吃肉
    2021-02-04 02:28

    In Controller you can check like this: Before if (ModelState.IsValid)

    if (model.party_type == 'p')
    {
       this.ModelState.Remove("surname");
    }
    

提交回复
热议问题