如何检测,如果表单字段已经改变,而无需使用隐藏域 [英] How to detect if form field has changed without using hidden field

查看:174
本文介绍了如何检测,如果表单字段已经改变,而无需使用隐藏域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ASP.NET MVC 3,并有必要,如果表单字段已经在服务器端更改检测。我知道使用的技巧与隐藏字段,但我不知道是否有一种方法只需使用API​​?

I am using ASP.NET MVC 3 and have a need to detect if the form field has been changed on the server side. I know about using tricks with hidden fields, but I was wondering if there is a way to do it by just using the API?

基本上,我有编辑屏幕为我的模型和领域之一是一个可选的ID可以被指定。如果指定了场,我必须确保它是唯一的(没有其他的模式有它)。因此,编辑控制器上,我要运行验证,但只有在该领域已被更改。

Basically, I have edit screen for my model and one of the fields is an optional id that can be specified. If the field is specified, I have to insure it is unique (no other model has it). So on the edit controller, I want to run the validation but only if that field has been changed.

请注意,我并​​不需要知道previous值与新的价值,只是如果字段值已经改变了。

Please note, I don't need to know previous value vs. new value, just if the field value has changed.

推荐答案

您必须保留旧值的副本某处,并做比较。你可以将其存储在您的视图模型。

You will have to keep a copy of the old value somewhere, and do the comparison. You may store it in your View Model.

这篇关于如何检测,如果表单字段已经改变,而无需使用隐藏域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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