ASP.NET MVC2 - 自定义模型绑定器示例
我试图找到一些为我需要处理的独特绑定场景构建自定义模型绑定程序的示例,但我找到的所有文章都是针对旧版本的 MVC,这些版本在 MVC2 中不再相关。我一直在参考 DefaultModelBinder 源代码,试图对我需要做的事情有一个总体的感觉,但它比我的场景要复杂得多,而且我在隔离我需要实现的特定逻辑时遇到了困难。
我的目标是获取复选框/文本框对的集合,对于所有选中的对,我想创建复选框值和关联文本框值的键/值对。聚合这些数据后,我需要对集合进行一些字符串序列化,以便可以将其存储在所需模型类型的字符串属性中。我已经以可管理的格式从表单发送数据,这将允许我将给定的复选框与特定的文本框相关联,这只是弄清楚如何将所有部分获取到我需要的地方的问题。
有谁知道一些可以帮助我开始构建自定义模型绑定程序的最新教程?
I am trying to find some examples of building a custom model binder for a unique binding scenario I need to handle, but all of the articles I found were for older versions of MVC which are no longer relevant in MVC2. I've been referencing the DefaultModelBinder source code to try to get a general feel for what I need to do, but it's entirely more complicated than my scenario and I'm having trouble isolating the specific logic I need to implement.
My goal is to take a collection of Checkbox/Textbox pairs and for all of the Checked pairs I would like to create a key/value pair of the Checkbox's value and the associated Textbox's value. After aggregating this data I need to do some string serialization on the collection so I can store it in a string property of the desired Model type. I already the data being sent from the form in a manageable format which will allow me to relate a given Checkbox to a specific Textbox, it's just a matter of figuring out how to get all the pieces where I need them.
Does anyone know of some up-to-date tutorials that can get me started with building a custom model binder?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道为什么您认为自 MVC 1 以来关于自定义模型绑定器发生了很多变化。但如果我明白你想要做什么,那应该相当容易。
您的行动:
这是您正在寻找的信息吗?
I don't know why you think a lot has changed since MVC 1 regarding custom model binders. But If I understand what you are trying to do, it should be fairly easy.
And your action :
Was that the kind of information you are looking for?
看一下 自定义 MVC 模型绑定器。
Take a look at several examples of Custom MVC Model binders on my blog.