MVC3 Prep 在验证之后但在提交之前输入?
我有一个表单,其中有一个部分具有动态数量的输入,具体取决于用户选择的选项。当配置回发到服务器时,我想将该部分的不同值连接到一个 xml 字符串中,并将它们作为一个值存储在数据库中。字段的可能组合是有限的;三种可能性中的每一种都构建为部分视图,我在加载时包含该视图,并在指定配置类型的下拉列表发生更改时通过 ajax 重新加载。
每个分部视图都是类型化的,并且具有与其关联的验证属性。
这就是我想要做的:单击提交按钮后,我希望对所有字段运行验证,但在实际提交表单之前,我想调用脚本来构建 xml 字符串并将其存储在隐藏输入中。
如何在验证和提交之间“注入”一个步骤,而无需执行大量自定义工作?
I have a form that has a section with a dynamic number of inputs, depending on the options the user has chosen. When the configuration posts back to the server, I want to concatenate the different values of that section into an xml string and store them in the database as one value. The possible combinations of fields are finite; each of the three possibilities is built as a partial view that I include on load, and reload via ajax if the dropdown specifying the type of config changes.
Each partial view is typed, and has validation properties associated with it.
Here's what I want to do: Upon the submit button being clicked, I want validation to run against all fields, but before actually submitting the form, I want to invoke a script to build the xml string and store it in a hidden input.
How do I "inject" a step between the validation and submission without having to do a bunch of custom work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么在验证之后完成它很重要?只需挂钩您的提交按钮单击事件,然后调用提交。因此,如果表单无效,它会起到一些作用。确实没什么大不了的。
Why does it matter that it be done after validation? Just hook your submit button clicked event, then call submit. So it does a little work if the form isn't valid. Not a huge deal really.