从Ajax调用获取表单时MVC2客户端验证不工作 [英] MVC2 Client Validation isn't working when getting form from ajax call

查看:113
本文介绍了从Ajax调用获取表单时MVC2客户端验证不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用MVC2客户端验证在通过$不用彷徨渲染的局部视图。但是,客户端验证是行不通的。我不太清楚这笔交易是什么。

I'm trying to use MVC2 client-side validation in a partial view that is rendered via $.get. However, the client validation isn't working. I'm not quite sure what the deal is.

[Required(ErrorMessage = "Email is required")]
public string Email { get; set; }

<% using ( Ajax.BeginForm( new AjaxOptions { Confirm = "You sure?" } ) ) { %>
<%: Html.TextBoxFor( m => m.Email, new { @class = "TextBox150" } )%>
<%= Html.ValidationMessageFor( m => m.Email )%>
<input type="submit" value="Add/Save" style="float: right;" />
<% } %>

我没有做什么特别的渲染局部视图。只是把HTML到一个div并显示在模式弹出它。

I'm not doing anything special to render the the partial view. Just putting the html into a div and showing it in a modal popup.

在一个侧面说明,没有人知道是否有可能与客户端验证提交表单没有提交按钮?

On a side note, does anyone know if it's possible to submit the form with client validation without a submit button?

推荐答案

前段时间我写了这个问题后,你可以使用它作为您的情况起始点(你将不得不修改,您拨打的地方功能并通过正确的元素来处理):
http://tpeczek.blogspot.com/2010 /04/making-aspnet-mvc-2-client-side.html

Some time ago I wrote a post about this issue, you might use it as start point in your situation (you will have to modify the place where you call the functions and pass correct element to process): http://tpeczek.blogspot.com/2010/04/making-aspnet-mvc-2-client-side.html

这篇关于从Ajax调用获取表单时MVC2客户端验证不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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