我正在创建一个MVC 3 Web应用程序.我想在我的实体类上使用Data Annotations,然后在回发到服务器之前使用不显眼的客户端验证.这在定期发布时工作正常.如果任何字段无效,我会得到验证和验证摘要.但是,我想通过ajax和json回发信息.如何首先在客户端"手动"验证表单,然后将我的ajax发布回服务器.以下是我的代码的摘要版本.
public class Customer
{
[Required(ErrorMessage = "The customer's first name is required.")]
public string FirstName { get; set; }
[Required(ErrorMessage = "The customer's last name is required.")]
public string LastName { get; set; }
}
<% using (Html.BeginForm()) { %>
<%: Html.LabelFor(model => model.FirstName, "First Name")%>
<%: Html.TextBoxFor(model => model.FirstName, new { @class = "TextBox", id = "Customer.FirstName" })%>
<%: Html.ValidationMessageFor(model => model.FirstName, "*")%>
<%: Html.LabelFor(model => model.LastName, "Last Name")%>
<%: Html.TextBoxFor(model => model.LastName, new { …Run Code Online (Sandbox Code Playgroud) 在我的asp mvc应用程序中,我使用标准客户端验证(DataAnnotations + MicrosoftAjax.js + MicrosoftMvcValidation.js).我需要在成功/不成功的客户端验证后显示一些弹出消息(jGrowl)(因此我不能使用ModelState.IsValid).所以我搜索一些标准的标志,指示客户端验证状态.有人知道吗?它存在吗?