简体   繁体   English

如何在ASP.NET Web窗体中创建自定义模型绑定程序?

[英]How do i create a custom model binder in ASP.NET Web Forms?

I'm using ASP.NET Web Forms and can't migrate to ASP.NET MVC right now. 我正在使用ASP.NET Web窗体,现在无法迁移到ASP.NET MVC。 I love the way the MVC team implemented a custom IHttpHandler, or HttpModule (Not sure which one) that gets the JSON data passed in from an Client Side Ajax request and passes the data into the action method on the requested page. 我喜欢MVC团队实现自定义IHttpHandler或HttpModule(不确定哪个)的方式,该方式将从客户端Ajax请求中传入JSON数据,并将该数据传递到所请求页面上的action方法中。

I want to be able to intercept a Http Request, retrieve that JSON/"Query String Parameters", and call a method on the page while passing the retrieved data as it's parameter. 我希望能够拦截Http请求,检索JSON /“查询字符串参数”,并在页面上调用方法,同时将检索到的数据作为参数传递。

Currently, i've implemented a custom route and it works fine. 目前,我已经实施了一条自定义路线,并且效果很好。 The only part that is missing for me is the "Custom Model Binder" as the call it in ASP.NET MVC. 我唯一缺少的部分是在ASP.NET MVC中调用的“自定义模型绑定器”。

Please can someone help me with a clue as to how i can go about it. 请有人能帮我一个线索,告诉我我该怎么做。

Have you considered ASP.NET MVVM ? 您是否考虑过ASP.NET MVVM

ASP.NET MVVM provides a framework to implement the Model-View-ViewModel pattern, aka the Presentation Model pattern in ASP.NET projects. ASP.NET MVVM提供了一个框架来实现Model-View-ViewModel模式,也就是ASP.NET项目中的Presentation Model模式。 Developers can take advantages of Dependency Injection and Event Broker to write concise, elegant and business focused code. 开发人员可以利用Dependency Injection和Event Broker编写简洁,优雅且以业务为中心的代码。

The ASP.NET MVVM offers the following benefits: ASP.NET MVVM具有以下优点:

  • Leverage ASP.NET functions, such as web form, user control and data binding 利用ASP.NET功能,例如Web表单,用户控件和数据绑定
  • Achieve a clear separation of concerns 明确分离关注点
  • Facilitate test driven development (TDD) 促进测试驱动开发(TDD)
  • Write and maintain simpler code using the attribute annotations 使用属性注释编写和维护更简单的代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM