开发者

ASP.NET MVC 3 Remote validation to allow original value

开发者 https://www.devze.com 2023-02-06 02:54 出处:网络
I have a Remote attribute on the email property of my User model. When I create a new user, it works create and tells the users that an e-mail is already in use. Now I\'m having a problem in my editin

I have a Remote attribute on the email property of my User model. When I create a new user, it works create and tells the users that an e-mail is already in use. Now I'm having a problem in my editing form (if the user wants to updates values). It tells the user that his/her e-mail is alread开发者_运维知识库y in use, I don't want it to give that message when the e-mail that's in use is the one that's registered to the user. How can I tweak the Remote attribute to behave?


I figured it out.

In my view, I put @Html.Hidden("InitialEmail", Model.Email)

On my Model, I put [Remote("IsEmailUsed", "User", AdditionalFields="InitialEmail")]

And then in my controller action, I have public JsonResult IsEmailUsed(string email, string initialEmail) which will allow the initial e-mail to be valid.

0

精彩评论

暂无评论...
验证码 换一张
取 消