Asp.net MVC 3 为 TemplateHint 注入 UserControl

发布于 2024-09-26 04:32:31 字数 336 浏览 1 评论 0原文

是否可以以某种方式利用 Asp.net MVC 3 中的依赖项注入(使用 Forms ViewEngine)从另一个库注入 UserControls?我已经在使用 MEF 将其他一些东西加载到我的 MvcApplication 中。

我需要这个,因为我想构建一个具有可扩展类型系统的系统。我希望类型供应商能够为提供的类型注入自定义控件。我已经有一个自定义 MetadataProvider,它知道如何处理提供的类型(它设置 ModelMetadata.TemplateHint 属性)。

问题是我可以在哪里插入 MEF,以便正确处理 TemplateHint,并在调用 Html.EditorForModel 时显示自定义控件

Is it possible to somehow leverage the dependency injection in Asp.net MVC 3 (using the Forms ViewEngine) to inject UserControls from another library? I am already using MEF to load some other stuff into my MvcApplication.

I need this because I want to build a system with an expandable type system. I want the type vendor to be able to inject custom controls for the provided type. I already have a custom MetadataProvider that knows how to handle the provided types (it sets the ModelMetadata.TemplateHint property).

The question is where can I plug in with MEF, so that the TemplateHint gets properly handled, and a custom control is dispalyed upon caling Html.EditorForModel

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

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

发布评论

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

评论(1

白云不回头 2024-10-03 04:32:31

我想不出使用 MVC 3 beta 中当前的服务定位器基础设施来做到这一点的方法。不过,我可以想到两种替代方法:

  1. 使用一个编辑器模板,它不是将 HTML 委托呈现给您的自定义控件并返回其输出。
  2. 编写您自己的 ViewEngine,它可以执行部分​​视图的查找(路径的形式为“EditorTemplates/YourTypeName”等)并返回一个知道如何与您的自定义控件通信的视图。

I can't think of a way to do this using the current Service Locator infrastructure in MVC 3 beta. I can think of 2 alternative appraoches though:

  1. Have an editor template that instead of rendering the HTML delegates to your custom controls and returns their output.
  2. Write your own ViewEngine that can perform lookups for partial views (the paths will be of the form "EditorTemplates/YourTypeName" etc.) and return a view that knows how to talk to your custom controls.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文