ASP.NET MVC 3 Remote validation to allow original value

谁说胖子不能爱 提交于 2020-01-22 10:01:48

问题


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 already 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?


回答1:


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.



来源:https://stackoverflow.com/questions/4778151/asp-net-mvc-3-remote-validation-to-allow-original-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!