问题标签 [remote-validation]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
5 回答
8396 浏览

jquery - How to get unobtrusive jquery remote validator to perform async..?

In an MVC3 app, using jquery unobtrusive validation, and a view/model with a [Remote] validator: I am trying to disable the submit button and display a wait icon during remote validation, and when a valid form is submitted to the server. I thought I had it nailed until I tried it in IE8.

The problem was, GC and FF were not firing the form's submit event when the form was invalid, so I just disabled the submit button during this event. However IE8 is firing this event when the form is invalid, causing the user to never be able to click it again. (IE8 does not submit the form, but the event is fired.)

I tried attaching a function to the submit button's click event. In there, I disabled the submit button, showed the wait icon, and had this:

The problem is, the ajax setup call is not really turning off async. It does if I move it out of the click function, but then it disables async for everything. Instead, the page alerts "true" immediately, tested by setting a breakpoint on the remote validation action method.

Any ideas?

Additional Note:

I forgot to mention, in IE8, the submit event is only being fired when the text box in question fails a validation that can happen on the client. For example, if it fails required or regex, submit() is fired. For the remote validation action method, it is not fired. However, as soon as it fails a client validation, subsequent remote validations also trigger the IE8 submit event.

Response to Russ Cam (comment #1)

Here is the relevant code in the viewmodel:

I'm glad you had me look at the rendered <form>. The form tag and input elements look like this:

I never saw the novalidate="novalidate" attribute until now. Here is what it looks like in the cshtml file:

I am also using anti-forgery token, if that makes a difference. Thanks.

0 投票
1 回答
308 浏览

asp.net-mvc-3 - 视图模型中的 RemoteAttribute 和相应操作方法中的 ActionNameAttribute (MVC3)

我刚刚发现使用 RemoteAttribute 的远程验证将不起作用,除非:

  1. 远程验证的操作方法没有 [ActionName] 属性,或者
  2. 远程验证的操作方法具有 [ActionName] 属性,该属性是与实际操作方法名称不区分大小写的匹配项。

使用以下内容,MVC 会抛出 InvalidOperationException “找不到远程验证的 url。”:

知道为什么吗?如果这有所作为,我正在使用 T4MVC。

0 投票
1 回答
2113 浏览

jquery - ASP.Net MVC3:远程验证调用未触发

我有一个数据输入表单,它设置了远程验证来检查数据库中某个字段的现有值。

这是发生的事情:

  1. 转到创建页面(数据输入表单)。为字段输入值 X。

  2. 场失去焦点。调用远程验证。Fiddler 显示呼叫。

  3. 单击保存。记录被保存;页面切换到索引页面。

  4. 再次转到创建页面。再次为字段输入值 Y。

  5. 场失去焦点。调用远程验证(每个 Fiddler)。

  6. 单击保存。记录被保存;页面切换到索引页面。

  7. 再次转到创建页面并输入 X(再次)作为字段。

  8. 场失去焦点。什么都没发生。不调用远程验证(每个 Fiddler)。

  9. 单击保存。不调用远程验证。页面尝试保存记录,但数据库将其吐回。

就好像创建页面记住了该字段的先前值也是 X,并且没有重新验证它,因为它没有改变,即使我在此期间去过其他页面。

我没有将模型传递给 Create 视图:我无法想象它是从哪里得到的,即该字段具有正在(或未)更改的先前值。

据我所知,OutputCache没有被使用。如果重要的话,我在 IE 8 上。

0 投票
1 回答
19322 浏览

asp.net-mvc - 如何在远程验证中使用多个 AdditionalFields - asp.net mvc

我需要在我的 ASP.NET MVC 4 (C#) 应用程序中使用远程验证来验证名字、姓氏和电子邮件地址组合的副本。远程验证只接受一个 AdditionalFields,如下:

如何为组合添加电子邮件地址?

0 投票
1 回答
641 浏览

asp.net-mvc-3 - ASP.Net mvc 3.0 远程验证

我有这个问题:

我正在验证一个模型,其中 2 个属性的总和不能大于 100。为此,我使用如下:

在我的模型中,这些是我的属性:

我的 ValidationController 如下:

我的看法如下:

这很好用。问题如下:假设prevTextWidth用户插入的是55,然后他插入46textboxWidth,这里验证失败,textboxWidth并且突出显示。

但是如果现在用户将 prevTextWidth 的 de 值更改为 54 会发生什么?验证赢得了t fail, but thetextboxWidth will continue to be highlighted and not valid. The only way to make it valid is to re-insert the value oftextboxWidth`。

那么有没有办法同时验证两个属性,而不是重新插入第二个值以使其有效?

提前致谢,

马蒂亚斯

0 投票
3 回答
1504 浏览

asp.net-mvc-3 - ASP.NET MVC 3:模型级客户端或远程验证

我需要在 MVC 3 编辑页面中进行一些模型级验证。(具体来说,我需要确认填写了字段 A 或字段 B,但不能同时填写。)

我想执行客户端验证以及服务器端验证,这意味着要么使用远程验证,要么实现重复验证代码。我都可以。

我已经阅读了许多关于滚动您自己的服务器端模型级验证的文章,但没有一篇文章涉及实现客户端验证。(我不知道——我相信有人可以告诉我——模型级客户端验证是否易于使用 jQuery 验证设置。)

我还阅读了有关从头开始实现您自己的远程验证的信息,我可能必须这样做,因为 Remote 属性仅是属性级的。

我读过这个问题,这与我的相同,但唯一真正正确的链接似乎并没有说明回答者所说的内容。

所以,我的问题是:是否有一种简单、相对省力的方法来实现服务器+客户端模型级验证,无论是否使用远程组件?是否有一个很好的博客文章或网页可以解释这一点?

0 投票
0 回答
697 浏览

ajax - MVC3 Razor - 远程验证未触发

我尝试实现“忘记密码”机制,我认为最好在重置密码和发送电子邮件之前检查用户名和电子邮件地址。我这样做了:





我无法触发“远程”验证,无论是客户端还是服务器端(提交时)。但是,“必需”验证按预期工作。

我被卡住了,请提出解决方案,提前谢谢你。

0 投票
1 回答
239 浏览

asp.net-mvc-3 - 在哪里可以找到要在 HTML Helper 或 EditorTemplate 中使用的 RemoteValidation 详细信息?

我目前有一个 MVC3 站点,我在其中显示具有特定格式的 DateTime 字段,即大写 (DD-MON-YYYY)。

我为此创建了以下 DateTime.ascx EditorTemplate,并且我添加了一个自定义 data-datepicker 属性,该属性被一些自定义 javascript 拾取以将 Jquery UI Datepicker 添加到该字段。<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>

我遇到的问题是,当我使用 EditorTemplate 时,我丢失了输入框上的所有 RemoteValidation 属性。显然是因为我没有专门添加它们!

有人可以指出我可以在模型或模型元数据中找到所需信息的正确方向,以便我可以使用远程验证和 JQueryUI 日期选择器构建输入框吗?

这是我目前从 EditorTemplate 得到的:

这就是我最终想要的:

有几点需要注意:

  • 如果需要,我愿意使用 HTMLHelper。我不限于 EditorTemplate
  • 我在控制器上有不同的 RemoteValidation 操作,用于不同的日期。所以我不能只是硬编码验证网址。我需要查找模型中字段上装饰的远程属性的值。
  • 同样,data-val-remote 值也需要基于模型字段上的 RemoteAttribute 加载。

有没有人有任何想法?

0 投票
2 回答
4448 浏览

asp.net-mvc-3 - MVC3 远程验证未触发?

我创建了一个非常简单的测试项目来说明问题。

我的模特班

我的控制器

而我的看法

还有我的 web.config

这里没有什么特别的。我有一个具有 3 个属性的模型类。第一个是必需的,第二个是远程验证,我相信我已经正确地创建了动作方法。我将 break piont 设置为ValidateProperty2起作用,它永远不会被调用。

我也用过FireBug,同样的东西客户端甚至不尝试调用服务器端。

这里的代码有什么问题?

编辑1:我想我得到了一些东西,远程验证只会在控件(例如文本框)在侧面具有值时触发。空控件永远不会触发验证。在我的情况下,我实际上尝试实现更复杂的逻辑,即使控制文本为空,我也需要触发验证(以检查其他属性的值)。甚至可能吗?

0 投票
1 回答
1472 浏览

asp.net - MVC3 远程验证

我目前正在使用 MVC3 设置远程验证,以便在用户选择的用户名已经存在时收到警报。从最重要的部分开始,一切都已设置并正常工作,没有显示错误消息。如果我提交表单,则会在页面刷新并添加相关模型状态错误时显示错误消息。

无论如何用 Json 结果刷新模型验证摘要?