MVC 和 Umbraco 集成

发布于 2024-08-12 07:17:00 字数 357 浏览 6 评论 0原文

我已按照 http://memoryleak.me 中的步骤操作.uk/2009/04/umbraco-and-aspnet-mvc.html 并成功地将 MVC 集成到 Umbraco 中,但我仍然遇到一个对我来说至关重要的问题。

有什么方法可以继承 MVC 视图中 Umbraco 定义的模板吗? 据我了解,问题在于 Umbraco 模板仅在运行时变成 HTML,并且 doctype 属性(如 @nodeName)无法识别,并因此引发“对象空引用”异常。

I've followed the steps from http://memoryleak.me.uk/2009/04/umbraco-and-aspnet-mvc.html and integrated MVC in Umbraco with success, but I still have a problem which is critical for me.

Is there any way to inherit the Umbraco defined templates in an MVC view?
As I understand the problem is that the Umbraco templates become HTML only at runtime and the doctype properties, as @nodeName, are not recognized and "Object null reference" exception being thrown because of this.

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

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

发布评论

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

评论(4

旧城空念 2024-08-19 07:17:00

这个问题确实很老了,与当前版本的 Umbraco 无关。

以防万一有人还不知道 - 自 2013 年 (v6) 以来的所有 Umbraco 版本都支持 MVC

This question is really old and not relevant to the current versions of Umbraco.

Just in case anybody is still not aware - All versions of Umbraco since 2013 (v6) support MVC

三人与歌 2024-08-19 07:17:00

看过博客文章后,似乎这实际上并未与 Umbraco 集成,而是与 Umbraco 一起工作。

因为它实际上是它自己的 HttpHandler。这意味着它绕过了 Umbraco Httphandler 以及与模板和 CMS 本身相关的一大堆 Umbraco 功能。

如果不修改核心应用程序(在版本 4+ 中),让 MVC 使用 Umbraco 模板(可能)是不可能的。然而,这并不意味着您不能将 MVC 与 Umbraco 一起使用,并将 Umbraco 充当 MVC 应用程序的内容存储库。

您可以轻松创建 MVC 控制器,从 Umbraco 提取数据并将其提供给您的视图。例如,您可以使用 Umbraco Linq2Umbraco 来实现此目的。

如果您提供更多有关您所得到的精确错误以及您想要实现的目标的更多详细信息,那么解决方案可能在于您如何构建应用程序,而不是试图强行使用 Umbraco 4+ 来做一些本机的事情Umbraco 5(计划于今年某个时候发布)。 5 的源代码位于 Codeplex 上,可能是查看 Umbraco 核心如何使用的好地方团队正在接近这一点。

这里有一个关于此的旧讨论:http://forum.umbraco。 org/yaf_postst5106_Using-ASPNET-MVC-with-Umbraco.aspx

以及最近的版本:http://our.umbraco.org/forum/getting-started/installing-umbraco/2668-Use-Umbraco-with-aspnet-MVC

进一步的讨论可以在这里找到:http: //our.umbraco.org/forum/developers/extending-umbraco/17523-Umbraco-461-and-MVC-3

甚至更多:
http://our .umbraco.org/forum/developers/extending-umbraco/6837-Umbraco-Website-And-MVC-Website-In-ONE

Having had a look at the blog post it seems that this is not actually integrated with Umbraco but working alongside Umbraco.

In that it is effectively its own HttpHandler. This means it is bypassing the Umbraco Httphandler and a whole bunch of Umbraco functionality relating to templates and the CMS itself.

Getting MVC to utilise Umbraco templates is (probably) not possible without modifications to the core application (in version 4+). However that doesn't mean you can't use MVC alongside Umbraco with Umbraco acting as a content repository for a MVC application.

You could easily create MVC controllers which pulled data from Umbraco and made that available to your views. For example you could use Umbraco Linq2Umbraco for this.

If you give more details as to the precise errors you are getting and exactly what you are trying to achieve, it may be the solution is in how you structure your application rather than attempting to brute force Umbraco 4+ to do something that will be native in Umbraco 5 (which is scheduled for release some time this year). The source code for 5 is on Codeplex and may be a good place to have a look and see how the Umbraco core team are approaching this.

There is an old discussion about this here: http://forum.umbraco.org/yaf_postst5106_Using-ASPNET-MVC-with-Umbraco.aspx

and more recently here: http://our.umbraco.org/forum/getting-started/installing-umbraco/2668-Use-Umbraco-with-aspnet-MVC

Further discussion can be found here: http://our.umbraco.org/forum/developers/extending-umbraco/17523-Umbraco-461-and-MVC-3

and even more here:
http://our.umbraco.org/forum/developers/extending-umbraco/6837-Umbraco-Website-And-MVC-Website-In-ONE

浪漫之都 2024-08-19 07:17:00

您可以考虑编写一些 HtmlHelper,而不是尝试使用 Umbraco 控件使用 umbraco.NodeFactory 的扩展方法。 Node 类来获取您尝试在视图中显示的内容。编写模仿(或根据您的需要进行简化)umbraco.presentation.templateControls.Itemumbraco.presentation.templateControls.Macro 的方法可能对您来说就足够了。

编辑

我沿着这条路取得了一些成功。我还查看了 MVC 源代码以了解如何
部分视图被添加到底层 Web 表单控件集合中。我最终编写了一个继承自 umbraco.presentation.templateControls.Macro 类的类,它看起来很像 System.Web.Mvc.ViewUserControl 类。

Rather than trying to use the Umbraco controls, you might consider writing some HtmlHelper extension methods that use the umbraco.NodeFactory.Node class to obtain the content you're trying to display in your views. Writing methods that mimic (or simplify based on your needs) umbraco.presentation.templateControls.Item and umbraco.presentation.templateControls.Macro may be enough for you.

EDIT

I went down this path with some success. I also took a look at the MVC source to find out how
partial views were being added to the underlying web forms controls collection. I ended up writing a class that inherits from the umbraco.presentation.templateControls.Macro class that looks a lot like the System.Web.Mvc.ViewUserControl class.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文