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

发布于 2024-12-12 19:01:37 字数 654 浏览 1 评论 0原文

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

发生的情况如下:

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

  2. 字段失去焦点。称为远程验证。 Fiddler 显示调用。

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

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

  5. 字段失去焦点。调用远程验证(根据 Fiddler)。

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

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

  8. 字段失去焦点。什么也没发生。没有调用远程验证(每个 Fiddler)。

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

就好像“创建”页面记住了该字段的先前值也是 X,并且不会重新验证它,因为它没有更改,即使我同时访问过其他页面。

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

据我所知,OutputCache 没有被使用。我用的是 IE 8,如果有的话。

I have a data entry form that has remote validation set up to check for existing values in the database for a certain field.

Here's what happens:

  1. Go to Create page (data entry form). Enter value X for field.

  2. Field loses focus. Remote validation is called. Fiddler shows the call.

  3. Click Save. Record is saved; page switches to Index page.

  4. Go to Create page again. Enter value Y again for field.

  5. Field loses focus. Remote validation is called (per Fiddler).

  6. Click Save. Record is saved; page switches to Index page.

  7. Go to Create page AGAIN and enter X (again) for field.

  8. Field loses focus. Nothing happens. No call to remote validation (per Fiddler).

  9. Click Save. No call to remote validation. Page attempts to save record but database spits it back.

It's as if the Create page is remembering that a previous value for the field was also X, and not revalidating it since it hasn't changed, even though I've been to other pages in the meantime.

I'm not passing a model to the Create view: I cannot imagine where it's getting the idea that that field has a previous value that's being (or not being) changed.

As far as I can tell, OutputCache is not being used. I'm on IE 8, if it matters.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

杀手六號 2024-12-19 19:01:37

好吧,我想我已经弄清楚了。这不仅是您不能使用 OutputCache 来缓存您的结果,您还必须明确表示不缓存您的验证结果。有关说明,请参阅此处例子。

ETA:另一件可能发生的事情是,如果第一个远程验证调用失败(如返回 500 错误),则不会再次调用它。因此,如果您预计您的验证例程会时不时地使用空数据调用(因为您的字段尚未填写),您需要使参数可为空并在验证代码中考虑到这一点。

OK, think I've figured it out. It's not just that you can't use OutputCache to cache your results, you have to explicitly say NOT to cache your validation results. See here for an explanation and example.

ETA: Another thing that can happen is that if the first remote validation call fails (as in, returns a 500 error) it won't get called again. Because of this, if you anticipate your validation routine being called with null data from time to time (because your fields aren't filled in yet) you need to make the parameters nullable and account for that in your validation code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文