ASP.NET MVC AJAX与HTML.ValidationMessageFor [英] ASP.NET MVC AJAX with HTML.ValidationMessageFor

查看:140
本文介绍了ASP.NET MVC AJAX与HTML.ValidationMessageFor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经习惯了做与AJAX的UpdatePanel的ASP.NET Web表单简单的方法。我理解的过程更加手工与MVC。

I'm used to the ASP.NET Webforms easy way of doing AJAX with UpdatePanels. I understand the process is much more artisanal with MVC.

在一个特定的情况下,我使用的数据注释来验证某种形式的投入。我用的是HTML.ValidationMessageFor助手来显示错误信息。如果我想使用AJAX来发布这张​​表格并出示此错误信息,会是什么过程?是否有可能保持HTML.ValidationMessageFor,并使其与AJAX工作吗?

In a specific case, I'm using Data Annotations to validate some form inputs. I use the HTML.ValidationMessageFor helper to show an error message. If I want to use AJAX to post this form and show this error message, what would be the process? Is it possible to keep the HTML.ValidationMessageFor and make it work with AJAX?

感谢你。

推荐答案

这篇文章可能会有所帮助: ScottGu的博客:ASP。 NET MVC 2:模型验证

This article might be helpful: ScottGu's blog: ASP.NET MVC 2: Model Validation.

在MVC中使用的验证可以是客户端和服务器端。要启用客户端验证使用的:

The validation used in MVC can be both client and server side. To enable client-side validation use the:

 <% Html.EnableClientValidation(); %>

声明放在你的看法。这否定了需要使用AJAX来发表您的表单到服务器,然后显示结果行内,当用户启用JavaScript都会有自己的客户方的验证。

declaration somewhere in your view. This negates the need to use AJAX to post your form to the server and then display the results inline, as users with javascript enabled will have their own clientside validation.

这篇关于ASP.NET MVC AJAX与HTML.ValidationMessageFor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆