How to disable field validation on MVC view?

后端 未结 2 1626
你的背包
你的背包 2021-01-21 18:30

I have an MVC 3 application. I have a model called UserModel that contains an email field, validated for unique with RemoteAttribute. I want to use UserModel on 2 Views - EditU

2条回答
  •  故里飘歌
    2021-01-21 19:10

    A good way to solve this is to pass the usermodel id as an adittional field into the remote validation method. This will be blank or null on create but populated on edit. You can then add logic to the remote validation method to check the id.
    See example below

    [Remote("ValidationMethod", "UserModel", AdditionalFields = "Id", ErrorMessage = "Error message")] 
    

提交回复
热议问题