如何验证从控制器返回的部分视图
我有一个带有 ajax.action 链接的视图页面,它从控制器返回部分视图并将其渲染为更新后的目标 id。但我无法对该部分视图执行客户端验证。
我可以有解决方案吗?
I have a view page with ajax.action link which returns a partial view from controller and render it to divid as updated target id. But I could not perform client side validation on that partial view.
Can I have solution for it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用ajax加载分部视图的html时,JavaScript代码不被执行是正常的。特别是如果您调用附加到 onload 事件的函数,因为该事件在 ajax 调用执行之前很久就被触发了。查看这篇文章 http ://adammcraventech.wordpress.com/2010/06/11/asp-net-mvc2-ajax-executing-dynamically-loaded-javascript/ 它描述了使用此方法可能遇到的各种问题。如果您想要更具体的答案,最好提供有关您的设置的更多信息,例如您正在使用的 .net/asp.net mvc 版本以及您尝试使用的验证框架。
When you load a partial view's html with ajax it is normal for the JavaScript code not to be executed. Especially if you have calls to functions attached to onload event since this event is fired long before the ajax call is executed. Check out this article http://adammcraventech.wordpress.com/2010/06/11/asp-net-mvc2-ajax-executing-dynamically-loaded-javascript/ it describes all sorts of problems that you can have with this approach. If you want a more specific answer it will be good to proivide more info on your setup like - what version of .net/asp.net mvc you are using and what validation framework are you trying to use.