English 中文(简体)
MVC and Umbraco integration
原标题:

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.

最佳回答

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 (6, 7 and now 8) support MVC

问题回答

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

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.

Umbraco is moving to donet core now https://umbraco.com/blog/net-core-alpha-release/





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签