动态设置必填字段
我很好奇如何动态设置模型的验证属性。例如,我经常有这样的视图:当用户处于某个角色时,某些字段应该是必需的,但当用户处于另一个角色时则不需要。我希望相应地设置服务器端和客户端验证。
I'm curious how I can dynamically set a model's validation attributes. For instance, I often have Views where certain fields should be required when a user is in a certain role, but not required when a user is in another role. I would like both the server-side and client-side validation to be set accordingly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这样的东西在服务器端不适合你吗?
一个示例用法是:
现在,对于客户端,
您必须将其注册以进行远程验证,如以下链接所述; http://forums.asp.net/t/1559594.aspx/1
希望你能明白,
克里斯
Wouldn't something like this work for you for the server side?
And an example usage will be;
Now for the client side of things,
Your going to have to register it for remote validation as described at the following link; http://forums.asp.net/t/1559594.aspx/1
Hope you get it,
Chris