<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:blogChannel="http://backend.userland.com/blogChannelModule" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
  <channel>
    <title>Shazwazza</title>
    <description>Shannon Deminick's blog all about .Net, Umbraco &amp; Web development </description>
    <link>http://shazwazza.com/</link>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>BlogEngine.NET 1.6.1.0</generator>
    <language>en-AU</language>
    <blogChannel:blogRoll>http://shazwazza.com/opml.axd</blogChannel:blogRoll>
    <dc:creator>Shannon Deminick</dc:creator>
    <dc:title>Shazwazza</dc:title>
    <geo:lat>0.000000</geo:lat>
    <geo:long>0.000000</geo:long>
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/Shazwazza" /><feedburner:info uri="shazwazza" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
      <title>Registering custom components in IoC for Umbraco 5 plugins</title>
      <description>&lt;p&gt;Sometimes you might need to add some of your own components to the IoC container in Umbraco 5 for your plugins to function. We’ve made this extremely easy to do and it only requires 2 steps:&lt;/p&gt; &lt;p&gt;Create a custom class that implements &lt;em&gt;Umbraco.Framework.DependencyManagement.IDependencyDemandBuilder . &lt;/em&gt;&lt;strong&gt;Ensure that this class does not have any constructor parameters otherwise it will not work. &lt;/strong&gt;There’s only one method to implement and you can use the containerBuilder parameter to add stuff to the IoC container:&lt;/p&gt;  &lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;&lt;p&gt;&lt;span style="color: #0000ff"&gt;void&lt;/span&gt; Build(IContainerBuilder containerBuilder, IBuilderContext context);&lt;/p&gt;&lt;/pre&gt;&lt;br&gt;&lt;/div&gt;

&lt;p&gt;Next you need to attribute your plugin (i.e. Tree, Editor, Menu Item, Property Editor, Surface Controller, etc….) to tell it which ‘Demand Builder’ to use. Easiest to explain with an example:&lt;/p&gt;
&lt;div style="border-bottom: silver 1px solid; text-align: left; border-left: silver 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: 'Courier New', courier, monospace; direction: ltr; max-height: 200px; font-size: 8pt; overflow: auto; border-top: silver 1px solid; cursor: text; border-right: silver 1px solid; padding-top: 4px" id="codeSnippetWrapper"&gt;&lt;pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"&gt;[DemandsDependencies(&lt;span style="color: #0000ff"&gt;typeof&lt;/span&gt;(MyCustomBuilder))]&lt;br&gt;[Tree(&lt;span style="color: #006080"&gt;"4883C970-2499-488E-A963-5204F6C6F840"&lt;/span&gt;, &lt;span style="color: #006080"&gt;"My Tree"&lt;/span&gt;)]&lt;br&gt;&lt;span style="color: #0000ff"&gt;public&lt;/span&gt; &lt;span style="color: #0000ff"&gt;class&lt;/span&gt; MyCustomTree : TreeController&lt;/pre&gt;&lt;br&gt;&lt;/div&gt;
&lt;p&gt;The above code will ensure that the ‘Demand Builder’ of type MyCustomBuilder will be executed when this plugin is loaded&lt;/p&gt;
&lt;p&gt;Thats it! Now you can add anything you need to the IoC container if you require this for your plugin.&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Shazwazza/~3/uFZiCqEmjTw/post.aspx</link>
      <author>admin</author>
      <comments>http://shazwazza.com/post/Registering-custom-components-in-IoC-for-Umbraco-5-plugins.aspx#comment</comments>
      <guid isPermaLink="false">http://shazwazza.com/post.aspx?id=b6da8c71-8aa8-4a2f-a3d1-157c95421e27</guid>
      <pubDate>Mon, 02 Jan 2012 01:23:00 +1900</pubDate>
      <category>Umbraco</category>
      <dc:publisher>admin</dc:publisher>
      <pingback:server>http://shazwazza.com/pingback.axd</pingback:server>
      <pingback:target>http://shazwazza.com/post.aspx?id=b6da8c71-8aa8-4a2f-a3d1-157c95421e27</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://shazwazza.com/trackback.axd?id=b6da8c71-8aa8-4a2f-a3d1-157c95421e27</trackback:ping>
      <wfw:comment>http://shazwazza.com/post/Registering-custom-components-in-IoC-for-Umbraco-5-plugins.aspx#comment</wfw:comment>
      <wfw:commentRss>http://shazwazza.com/syndication.axd?post=b6da8c71-8aa8-4a2f-a3d1-157c95421e27</wfw:commentRss>
    <feedburner:origLink>http://shazwazza.com/post.aspx?id=b6da8c71-8aa8-4a2f-a3d1-157c95421e27</feedburner:origLink></item>
    <item>
      <title>Umbraco v5 Surface Controller Forms</title>
      <description>&lt;p&gt;This post will show you how to create a form in Umbraco v5 using Surface Controllers. The information in this post assumes that you are familiar with Surface Controllers (see this &lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-5-Surface-Controllers.aspx" target="_blank"&gt;previous post&lt;/a&gt; if not) and with creating forms in ASP.Net MVC. &lt;/p&gt; &lt;h2&gt;Disclaimer&lt;/h2&gt; &lt;p&gt;&lt;em&gt;This post is about developing for Umbraco v5 (Jupiter) which at the time of this post is still under development. The technical details described below may change by the time Umbraco Jupiter is released. If you have feedback on the technical implementation details, please comment below.&lt;/em&gt;  &lt;h1&gt;Create a model&lt;/h1&gt; &lt;p&gt;The easiest way to create a form in MVC is to create a model that represents your form. This isn’t mandatory but then you’ll have to use some old school techniques like getting posted values directly from the HttpRequest object.&lt;/p&gt; &lt;p&gt;An example could be:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MySite.Models
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyTestModel
    {
        [Required]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; Name { get; set; }

        [Required]
        [Range(18,30)]
        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;int&lt;/span&gt; Age { get; set; }        
    }
}&lt;/pre&gt;
&lt;h1&gt;Create a Surface Controller&lt;/h1&gt;
&lt;p&gt;For this example we’ll assume that we’re creating a locally declared Surface Controller (not a plugin, &lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-5-Surface-Controllers.aspx" target="_blank"&gt;see the previous post for full details&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;Some code first and explanation after:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MySite.Controllers
{   
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MySurfaceController : SurfaceController
    {
        [HttpPost] 
        &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult HandleFormSubmit(
            [Bind(Prefix = &lt;span class="str"&gt;"MyTestForm"&lt;/span&gt;)]
            MyTestModel model)
        {
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!ModelState.IsValid)
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; CurrentUmbracoPage();
            }            
            
            &lt;span class="rem"&gt;//do stuff here with the data in the model... send&lt;/span&gt;
            &lt;span class="rem"&gt;// an email, or insert into db, etc...&lt;/span&gt;
            
            &lt;span class="kwrd"&gt;return&lt;/span&gt; RedirectToUmbracoPage(
                &lt;span class="kwrd"&gt;new&lt;/span&gt; HiveId(
                    &lt;span class="kwrd"&gt;new&lt;/span&gt; Guid(&lt;span class="str"&gt;"00000000000000000000000000001049"&lt;/span&gt;)));
        }
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Lets break down some parts of the above Controller code:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Namespace:&lt;/strong&gt; &lt;/em&gt;Generally you’ll put your locally declared controllers in the ~/Controllers folder, the above namespace reflects this.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Class:&lt;/strong&gt; &lt;/em&gt;The Surface Controller class is suffixed with the term ‘&lt;em&gt;SurfaceController’&lt;/em&gt;. This is a required convention (as per the previous post), without that suffix, the controller will not get routed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;[Bind] attribute: &lt;/em&gt;&lt;/strong&gt;In the code below you’ll see that we are creating the editor with a ‘prefix’ called ‘MyTestForm’. This ensures that each input element on the form will get its name prefixed with this value. For example:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;input&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text"&lt;/span&gt; &lt;span class="attr"&gt;name&lt;/span&gt;&lt;span class="kwrd"&gt;="MyTestForm.Name"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;This is a recommended practice however it is optional. If you don’t prefix your form controls then you don’t need to use the [Bind] attribute. Here’s a few reasons why this is a recommended practice:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Without the prefix, If there is more than 1 form rendered on your webpage and both are using the MVC validation summary, then both validation summaries will display the errors for both forms. When there is a prefix you can tell the validation summary to only display errors for the form with the specified prefix. 
&lt;li&gt;The MVC Html helpers will generate the html id for each element and without specifying a prefix and if you have more than 1 form rendered on your page you may end up with duplicate html element Ids. 
&lt;li&gt;If you create a scaffolded form with a custom model object such as doing: &lt;br&gt;&lt;br&gt;&lt;pre class="csharpcode"&gt;@{ var someModel = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyModel(); }
@Html.EditorFor(x =&amp;gt; someModel)&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;then MVC will automatically prefix your input fields with ‘someModel’ . For some reason MVC does this when the model name isn’t exactly ‘Model’.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;return CurrentUmbracoPage: &lt;/em&gt;&lt;/strong&gt;This method is built in to the base SurfaceController class and simply returns the currently executing Umbraco page without a redirect to it which is generally what you want to do in order to display any validation errors.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;return RedirectToUmbracoPage:&lt;/em&gt;&lt;/strong&gt; This method is built in to the base SurfaceController class and performs a redirect to a Umbraco page given an Id which is generally what you want to do when a form submission is successful. (chances are that you wont have a page with a Guid id of 00000000000000000000000000001234…. this is just an example :)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;NOTE: There is also a &lt;strong&gt;RedirectToCurrentUmbracoPage()&lt;/strong&gt; method!&lt;/em&gt;&lt;/p&gt;
&lt;h1&gt;Rendering a form&lt;/h1&gt;
&lt;p&gt;There are a few ways to render a form:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Directly in your Umbraco template/view 
&lt;li&gt;Using a &lt;a href="http://shazwazza.com/post/Partial-View-macros-in-Umbraco-v5.aspx" target="_blank"&gt;Partial View macro&lt;/a&gt; 
&lt;li&gt;Using a Child Action macro which renders a partial view&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Regardless of which you use to render a form, the markup will be very similar. Similar to MVC’s @Html.BeginForm, we have an &lt;strong&gt;@Html.BeginUmbracoForm&lt;/strong&gt; helper:&lt;/p&gt;&lt;pre class="csharpcode"&gt;@{
    var formModel = &lt;span class="kwrd"&gt;new&lt;/span&gt; MySite.Models.MyTestModel();
}

@&lt;span class="kwrd"&gt;using&lt;/span&gt;(Html.BeginUmbracoForm(&lt;span class="str"&gt;"HandleFormSubmit"&lt;/span&gt;, &lt;span class="str"&gt;"MySurface"&lt;/span&gt;))
{
    @Html.ValidationSummary(prefix: &lt;span class="str"&gt;"MyTestForm"&lt;/span&gt;)
    @Html.EditorFor(x =&amp;gt; formModel, &lt;span class="str"&gt;""&lt;/span&gt;, &lt;span class="str"&gt;"MyTestForm"&lt;/span&gt;)
    &amp;lt;input type=&lt;span class="str"&gt;"submit"&lt;/span&gt;/&amp;gt;
}&lt;/pre&gt;
&lt;p&gt;Here’s the breakdown of the above mark-up:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;Html.BeginUmbracoForm: &lt;/em&gt;&lt;/strong&gt;A normal MVC form would simply use Html.BeginForm which will create an action attribute for the html form tag with a URL of your controller’s action. In Umbraco however, we want the URL to be posted to the same as the URL being rendered (post back), so the BeginUmbracoForm call handles this all for us. It will create a form tag with the URL of the currently rendered Umbraco node and add some custom hidden fields to your form containing the values of where the data will actually post to (your Surface Controller’s action). The Umbraco front-end route handler will take care of all of this for you.&lt;/p&gt;
&lt;p&gt;The parameters passed in to BeginUmbracoForm will differ depending on if your Surface Controller is a plugin controller or a locally declared controller. In this example, its a locally declared controller so we just need to give it the action name and controller name. If its a plugin Surface Controller, you’ll need to give it the action and and the controller ID. There’s also a few overloads so that you can add additional html attributes to the rendered html form tag.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;@Html.ValidationSummary: &lt;/em&gt;&lt;/strong&gt;The native MVC ValidationSummary doesn’t let you target specific input tags via prefixes so we’ve created a ‘better’ one that does let you do that. In this example we’re telling the validation summary to only display errors for input values that are prefixed with “MyTestForm” which is real handy if you’re rendering a few forms on the same page and using a validation summary for each.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;@Html.EditorFor: &lt;/em&gt;&lt;/strong&gt;This is the native EditorFor method in MVC which lets you supply a prefix name which will be used for all of your input fields. The MVC methods for rendering individual input tags also have an overload to supply a prefix if you choose not to have it scaffold your form for you.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;formModel: &lt;/em&gt;&lt;/strong&gt;The above mark-up will scaffold the form for us based on the model that we created previously. This example creates an inline model object (formModel) to scaffold the form but if you had a strongly typed partial view with your model type, you could just as well use the view’s Model property.&lt;/p&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;/p&gt;
&lt;p&gt;And that’s pretty much it! Happy form making :)&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Shazwazza/~3/h7axU4P5W1s/post.aspx</link>
      <author>admin</author>
      <comments>http://shazwazza.com/post/Umbraco-v5-Surface-Controller-Forms.aspx#comment</comments>
      <guid isPermaLink="false">http://shazwazza.com/post.aspx?id=30f67ed8-bbdc-4541-bd9c-1649140cbebd</guid>
      <pubDate>Tue, 29 Nov 2011 20:22:00 +1900</pubDate>
      <category>Umbraco</category>
      <dc:publisher>admin</dc:publisher>
      <pingback:server>http://shazwazza.com/pingback.axd</pingback:server>
      <pingback:target>http://shazwazza.com/post.aspx?id=30f67ed8-bbdc-4541-bd9c-1649140cbebd</pingback:target>
      <slash:comments>4</slash:comments>
      <trackback:ping>http://shazwazza.com/trackback.axd?id=30f67ed8-bbdc-4541-bd9c-1649140cbebd</trackback:ping>
      <wfw:comment>http://shazwazza.com/post/Umbraco-v5-Surface-Controller-Forms.aspx#comment</wfw:comment>
      <wfw:commentRss>http://shazwazza.com/syndication.axd?post=30f67ed8-bbdc-4541-bd9c-1649140cbebd</wfw:commentRss>
    <feedburner:origLink>http://shazwazza.com/post.aspx?id=30f67ed8-bbdc-4541-bd9c-1649140cbebd</feedburner:origLink></item>
    <item>
      <title>Umbraco Jupiter Plugins - Part 5 - Surface Controllers</title>
      <description>&lt;p&gt;This is the fifth blog post in a series of posts relating to building plugins for Umbraco v5 (Jupiter). This post will explain what a Surface Controller is, what they can be used for and how to create one. &lt;/p&gt; &lt;h2&gt;Disclaimer&lt;/h2&gt; &lt;p&gt;&lt;em&gt;This post is about developing for Umbraco v5 (Jupiter) which at the time of this post is still under development. The technical details described below may change by the time Umbraco Jupiter is released. If you have feedback on the technical implementation details, please comment below.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Related Posts:&lt;/strong&gt;  &lt;ol&gt; &lt;li&gt;&lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-1.aspx"&gt;Umbraco Jupiter Plugins – Part 1&lt;/a&gt;  &lt;li&gt;&lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-2-Routing.aspx"&gt;Umbraco Jupiter Plugins – Part 2 – Routing&lt;/a&gt;  &lt;li&gt;&lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-3-Trees.aspx"&gt;Umbraco Jupiter Pluings – Part 3 – Trees&lt;/a&gt;  &lt;li&gt;&lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-4-Editors.aspx"&gt;Umbraco Jupiter Pluings – Part 4 – Editors&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt; &lt;h1&gt;What is a Surface Controller?&lt;/h1&gt; &lt;p&gt;A Surface Controller is an MVC controller that interacts with the front-end (or render layer) of Umbraco. An example of a Surface Controller could be a controller that has a &lt;a href="http://haacked.com/archive/2009/11/18/aspnetmvc2-render-action.aspx" target="_blank"&gt;Child Action&lt;/a&gt; used to display a Twitter Feed, or a controller that has an Action to accept some posted information from a form. Child Actions on Surface Controller will probably be primarily used for Child Action Macros in Umbraco v5. &lt;/p&gt; &lt;p&gt;Since Surface Controllers are plugins, this means that you can create a package that contains Surface Controllers to distribute whatever front-end functionality you like to Umbraco developers. Surface Controllers, just like Tree Controllers and Editor Controllers get automatically routed for you.&lt;/p&gt; &lt;h1&gt;Creating a Surface Controller&lt;/h1&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;Important convention: &lt;/strong&gt;All Surface controller names MUST be suffixed with ‘SurfaceController’. For example, if you are creating a Surface Controller to display system a Twitter feed, you might call your controller: TwitterFeed&lt;strong&gt;SurfaceController&lt;/strong&gt;. If you don’t follow this convention, you’re surface controller wont be routed.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;The first step is to create a class that inherits from the base Surface Controller class:&amp;nbsp; &lt;strong&gt;Umbraco.Cms.Web.Surface.SurfaceController &lt;/strong&gt;&lt;/p&gt; &lt;p&gt;The next step is to define some MVC Action’s to do whatever it is you’d like them to do. Here’s some examples:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Creating an action to partake in a Child Action Macro. To define this is very simple and follows the exact same MVC principles to creating a Child Action… just add a &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.childactiononlyattribute.aspx" target="_blank"&gt;ChildActionOnlyAttribute&lt;/a&gt; to your action method:&lt;/li&gt;&lt;/ul&gt;&lt;pre class="csharpcode"&gt;[ChildActionOnly]
&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult DisplayTwitterFeed()&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;ul&gt;
&lt;li&gt;Creating a child action to simply be used as a normal MVC child action which get rendered using @Html.Action or @Html.RenderAction 
&lt;li&gt;Create an action to handle some posted form data:&lt;/li&gt;&lt;/ul&gt;&lt;pre class="csharpcode"&gt;[HttpPost]
&lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult HandleMyFormSubmission(MyFormModel model) &lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;ul&gt;
&lt;li&gt;Maybe you’d like to track all links clicked on your page. You could use jquery to update all of your links on your page to point to your custom action URL with the real URL as a query string. Then your custom action will log the real link address and redirect the user to where they want to go.&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;Plugins vs Non-plugins&lt;/h2&gt;
&lt;p&gt;A Surface Controller ‘can’ be a plugin, meaning that you can create it as a plugin and distribute it as part of a package. However, if you are creating your own Umbraco website and do your development in Visual Studio like most of us, you don’t need to create a Surface Controller with a plugin definition and install it as part of a package, you can just define it locally just like a controller in a normal MVC project. If you do want to ship your Surface Controller as part of a package then you must attribute your Surface Controller with the SurfaceAttribute, and give it an Id. If you don’t do this then Umbraco will detect that its loading a Surface Controller plugin without an Id and throw an exception.&lt;/p&gt;
&lt;h2&gt;As a plugin&lt;/h2&gt;
&lt;p&gt;Standard practice for creating any kind of controller is to put your controllers in the ‘Controllers’ folder (this is not mandatory but a simple convention to follow). So If you’ve created a new project in Visual Studio, you’d create a folder called ‘Controllers’, then create your Surface Controller class with the SurfaceAttribute and an Id:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.Mvc;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Umbraco.Cms.Web.Context;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Umbraco.Cms.Web.Surface;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Umbraco.Framework;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MyProject.Controllers
{
    [Surface(&lt;span class="str"&gt;"98625300-6DF0-41AF-A432-83BD0232815A"&lt;/span&gt;)]
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TwitterFeedSurfaceController : SurfaceController
    {

    }
}&lt;/pre&gt;
&lt;p&gt;Because this Surface Controller is a plugin, you’ll need to attribute your project assembly (just like when creating Trees or Editor plugins). You can declare this in any of your classes or in the AssemblyInfo.cs file.&lt;/p&gt;&lt;pre class="csharpcode"&gt;[assembly: AssemblyContainsPlugins]&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;h2&gt;As a locally declared Surface Controller&lt;/h2&gt;
&lt;p&gt;This is pretty much identical to the above but you don’t have to include the SurfaceAttribute or attribute your assembly. If you’ve got an Umbraco v5 website that you’re working on you should just create a ~/Controllers folder to put your controller in, just as if you were creating a normal MVC project. Then you can create your Surface Controller:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.Mvc;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Umbraco.Cms.Web.Context;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Umbraco.Cms.Web.Surface;
&lt;span class="kwrd"&gt;using&lt;/span&gt; Umbraco.Framework;

&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MyProject.Controllers
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; TwitterFeedSurfaceController : SurfaceController
    {

    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;h1&gt;Using a Surface Controller&lt;/h1&gt;
&lt;p&gt;The usage of a Surface Controller really depends on what you’ve created your surface controller to do. Probably the 3 main ways to use them will be:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a ChildAction Macro by using the Macro UI in the back office and selecting a child action that you’ve declared on your Surface Controller, then render the macro in your template or inline in the WYSIWYG editor. 
&lt;li&gt;Directly render a child action declared on your Surface Controller by using &lt;em&gt;@Html.Action &lt;/em&gt;or &lt;em&gt;@Html.RenderAction&lt;/em&gt; 
&lt;li&gt;Create an Html form to post data to an action on your Surface Controller using &lt;em&gt;@Html.BeginUmbracoForm &lt;/em&gt;(more on this in the next blog post!)&lt;/li&gt;&lt;/ul&gt;</description>
      <link>http://feedproxy.google.com/~r/Shazwazza/~3/eF2EhvAbR8g/post.aspx</link>
      <author>admin</author>
      <comments>http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-5-Surface-Controllers.aspx#comment</comments>
      <guid isPermaLink="false">http://shazwazza.com/post.aspx?id=81945279-92e4-43c1-8b03-f77bd36758b7</guid>
      <pubDate>Tue, 29 Nov 2011 13:31:00 +1900</pubDate>
      <category>Umbraco</category>
      <dc:publisher>admin</dc:publisher>
      <pingback:server>http://shazwazza.com/pingback.axd</pingback:server>
      <pingback:target>http://shazwazza.com/post.aspx?id=81945279-92e4-43c1-8b03-f77bd36758b7</pingback:target>
      <slash:comments>7</slash:comments>
      <trackback:ping>http://shazwazza.com/trackback.axd?id=81945279-92e4-43c1-8b03-f77bd36758b7</trackback:ping>
      <wfw:comment>http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-5-Surface-Controllers.aspx#comment</wfw:comment>
      <wfw:commentRss>http://shazwazza.com/syndication.axd?post=81945279-92e4-43c1-8b03-f77bd36758b7</wfw:commentRss>
    <feedburner:origLink>http://shazwazza.com/post.aspx?id=81945279-92e4-43c1-8b03-f77bd36758b7</feedburner:origLink></item>
    <item>
      <title>Sharing Controller Actions with ControllerExtenders</title>
      <description>&lt;h1&gt;Why?&lt;/h1&gt; &lt;p&gt;If you wanted to be able to share Actions between controllers in .Net there is currently no official way to do it and that is probably because it might not be something that people have thought about doing very often before. Though once I started thinking about it I realized that this concept could be used for a variety of different purposes and that other people might potentially think of whole new ways to apply this concept. Here’s a couple use cases:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Separating logic out of large controllers  &lt;li&gt;Ability to distribute Controllers in DLLs whose Actions that could then be consumed by other people’s Controllers  &lt;li&gt;Support for a ‘Multiple inheritance’ class structure&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Again I think that there is some potential here for people to run with this concept in their own ways. Its probably not a concept that everyone will want/need to use, but you should know that it definitely can be done, and here’s how…&lt;/p&gt; &lt;h1&gt;ControllerExtender&lt;/h1&gt; &lt;p&gt;In order to extend your Controller with actions from another Controller, you’ll need to register your extension with a new class called &lt;em&gt;ControllerExtender&lt;/em&gt;. There’s a couple of ways to go about doing this, the nicest way is to use attributes on your Controller:&lt;/p&gt;&lt;pre class="csharpcode"&gt;[ExtendedBy(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(TestExtenderController))]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ContentEditorController : Controller
{....}&lt;/pre&gt;
&lt;p&gt;Otherwise there’s a few overloads on the ControllerExtender class to directly do this:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;//Where 'this' is the controller you are extending, generally called in the &lt;/span&gt;
&lt;span class="rem"&gt;//constructor of your controller&lt;/span&gt;
ControllerExtender.RegisterExtender(&lt;span class="kwrd"&gt;this&lt;/span&gt;, &lt;span class="kwrd"&gt;typeof&lt;/span&gt; (TestExtenderController));

&lt;span class="rem"&gt;//Where 'this' is the controller you are extending, generally called in the &lt;/span&gt;
&lt;span class="rem"&gt;//constructor of your controller&lt;/span&gt;
ControllerExtender.RegisterExtender&amp;lt;TestExtenderController&amp;gt;(&lt;span class="kwrd"&gt;this&lt;/span&gt;);

&lt;span class="rem"&gt;//This registration could be created in your global.asax &lt;/span&gt;
ControllerExtender.RegisterExtender&amp;lt;ContentEditorController, TestExtenderController&amp;gt;();&lt;/pre&gt;
&lt;p&gt;One important thing to note is that the &lt;em&gt;ControllerExtender&lt;/em&gt; uses the &lt;em&gt;DependencyResolver&lt;/em&gt; to create an instance of the extending controller class so you’ll need to ensure that your controllers are registered properly in IoC.&lt;/p&gt;
&lt;h2&gt;Illegal Extenders&lt;/h2&gt;
&lt;p&gt;The &lt;em&gt;ControllerExtender&lt;/em&gt; will not let you extend a controller by it’s same type of it’s same sub type. Also, nested extenders do not work (though the code could be modified to support this) therefore you cannot have Controller ‘A’ be extended by Controller ‘B’ which is extended by Controller ‘C’. In this scenario when rendering actions on Controller ‘A’, only actions on Controller ‘A’ and ‘B’ will be resolved. When rendering actions on Controller ‘B’ only actions on Controller ‘B’ and ‘C’ will be resolved.&lt;/p&gt;
&lt;h2&gt;Multiple Extenders&lt;/h2&gt;
&lt;p&gt;You can register multiple extenders for one Controller but because multiple extenders may have the same Action name/signature, only the first one that is found that is a match is used. It is therefor up to the developer to make sure they are aware of this.&lt;/p&gt;
&lt;h1&gt;Custom IActionInvoker&lt;/h1&gt;
&lt;p&gt;In order to facilitate the sharing of Actions a custom &lt;a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.iactioninvoker.aspx" target="_blank"&gt;IActionInvoker&lt;/a&gt; of type &lt;em&gt;ControllerExtenderActionInvoker&lt;/em&gt; needs to be registered on your controller. This is easy to do in the constructor of your controller:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; MyController()
{
    &lt;span class="kwrd"&gt;this&lt;/span&gt;.ActionInvoker = &lt;span class="kwrd"&gt;new&lt;/span&gt; ControllerExtenderActionInvoker();
}&lt;/pre&gt;
&lt;h1&gt;Source Code&lt;/h1&gt;
&lt;p&gt;The source code for all of this is pretty straight forward and boils down to 3 classes: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The static ControllerExtender class 
&lt;li&gt;The custom ControllerExtenderActionInvoker 
&lt;li&gt;The ExtendedByAttribute&lt;/li&gt;&lt;/ul&gt;
&lt;h2&gt;ControllerExtenderActionInvoker class&lt;/h2&gt;
&lt;p&gt;This class is responsible for finding and invoking the correct Action on a controller which takes into account any of the extenders registered for the currently executing Controller.&lt;/p&gt;
&lt;p&gt;The most up to date code can be found in the Umbraco 5 source code &lt;a href="http://umbraco.codeplex.com/SourceControl/changeset/view/5cc7972099a5#Source%2fLibraries%2fUmbraco.Cms.Web%2fMvc%2fActionInvokers%2fControllerExtenderActionInvoker.cs" target="_blank"&gt;HERE&lt;/a&gt;. &lt;/p&gt;
&lt;h2&gt;ControllerExtender class&lt;/h2&gt;
&lt;p&gt;This class is responsible for maintaining the extender registrations, it allows for creating registrations and returning registrations:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ControllerExtender
{

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Internal ConcurrentDictionary to store all registrations&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;readonly&lt;/span&gt; ConcurrentDictionary&amp;lt;Tuple&amp;lt;Type, Type&amp;gt;, Func&amp;lt;ControllerBase&amp;gt;&amp;gt; 
        Registrations
            = &lt;span class="kwrd"&gt;new&lt;/span&gt; ConcurrentDictionary&amp;lt;Tuple&amp;lt;Type, Type&amp;gt;, Func&amp;lt;ControllerBase&amp;gt;&amp;gt;();

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Registers the extender.&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;typeparam name="TController"&amp;gt;The type of the controller.&amp;lt;/typeparam&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;typeparam name="TExtender"&amp;gt;The type of the extender.&amp;lt;/typeparam&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RegisterExtender&amp;lt;TController, TExtender&amp;gt;()
        &lt;span class="kwrd"&gt;where&lt;/span&gt; TController : ControllerBase
        &lt;span class="kwrd"&gt;where&lt;/span&gt; TExtender : ControllerBase
    {
        var t = &lt;span class="kwrd"&gt;new&lt;/span&gt; Tuple&amp;lt;Type, Type&amp;gt;(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(TController), &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(TExtender));
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (Registrations.ContainsKey(t))
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(TExtender).IsAssignableFrom(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(TController)))
        {
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; InvalidOperationException
                (&lt;span class="str"&gt;"Cannot extend a controller by it's same type"&lt;/span&gt;);
        }

        Registrations.TryAdd(t, () =&amp;gt; DependencyResolver.Current.GetService&amp;lt;TExtender&amp;gt;());
    }

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Registers the extender.&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;typeparam name="T"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;param name="controllerToExtend"&amp;gt;The controller to extend.&amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RegisterExtender&amp;lt;T&amp;gt;(
        ControllerBase controllerToExtend)
        &lt;span class="kwrd"&gt;where&lt;/span&gt; T : ControllerBase
    {
        RegisterExtender(controllerToExtend, () =&amp;gt; DependencyResolver.Current.GetService&amp;lt;T&amp;gt;());
    }

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Registers the extender.&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;param name="controllerToExtend"&amp;gt;The controller to extend.&amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;param name="controllerExtender"&amp;gt;The controller extender.&amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RegisterExtender(
        ControllerBase controllerToExtend, 
        Type controllerExtender)
    {
        var t = &lt;span class="kwrd"&gt;new&lt;/span&gt; Tuple&amp;lt;Type, Type&amp;gt;(controllerToExtend.GetType(), controllerExtender);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (Registrations.ContainsKey(t))
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (controllerExtender.IsAssignableFrom(controllerToExtend.GetType()))
        {
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; InvalidOperationException
                (&lt;span class="str"&gt;"Cannot extend a controller by it's same type"&lt;/span&gt;);
        }

        Registrations.TryAdd(t, 
            () =&amp;gt; DependencyResolver.Current.GetService(controllerExtender) &lt;span class="kwrd"&gt;as&lt;/span&gt; ControllerBase);
    }

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Registers the extender.&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;typeparam name="T"&amp;gt;&amp;lt;/typeparam&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;param name="controllerToExtend"&amp;gt;The controller to extend.&amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;param name="extender"&amp;gt;The extender.&amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; RegisterExtender&amp;lt;T&amp;gt;(
        ControllerBase controllerToExtend, 
        Expression&amp;lt;Func&amp;lt;T&amp;gt;&amp;gt; extender)
        &lt;span class="kwrd"&gt;where&lt;/span&gt; T : ControllerBase
    {
        var extenderType = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(T);
        var t = &lt;span class="kwrd"&gt;new&lt;/span&gt; Tuple&amp;lt;Type, Type&amp;gt;(controllerToExtend.GetType(), extenderType);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (Registrations.ContainsKey(t))
            &lt;span class="kwrd"&gt;return&lt;/span&gt;;

        &lt;span class="kwrd"&gt;if&lt;/span&gt; (extender.GetType().IsAssignableFrom(controllerToExtend.GetType()))
        {
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; InvalidOperationException
                (&lt;span class="str"&gt;"Cannot extend a controller by it's same type"&lt;/span&gt;);
        }

        Registrations.TryAdd(t, extender.Compile());
    }

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Returns all registrations as a readonly collection&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; IEnumerable&amp;lt;KeyValuePair&amp;lt;Tuple&amp;lt;Type, Type&amp;gt;, Func&amp;lt;ControllerBase&amp;gt;&amp;gt;&amp;gt; 
        GetRegistrations()
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; Registrations;
    }

}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;h2&gt;ExtendedByAttribute class&lt;/h2&gt;
&lt;p&gt;This Attribute is used by the ControllerExtenderActionInvoker to created Extender registrations dynamically.&lt;/p&gt;&lt;pre class="csharpcode"&gt;[AttributeUsage(AttributeTargets.Class, AllowMultiple = &lt;span class="kwrd"&gt;true&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ExtendedByAttribute : Attribute
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; Type ControllerExtenderType { get; &lt;span class="kwrd"&gt;private&lt;/span&gt; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; ExtendedByAttribute(Type controllerExtenderType)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(ControllerBase).IsAssignableFrom(controllerExtenderType))
        {
            &lt;span class="kwrd"&gt;throw&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; ArgumentException
                (&lt;span class="str"&gt;"controllerExtenderType must be of type Controller"&lt;/span&gt;);
        }
        ControllerExtenderType = controllerExtenderType;       
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;</description>
      <link>http://feedproxy.google.com/~r/Shazwazza/~3/Y6vfDHNqqJE/post.aspx</link>
      <author>admin</author>
      <comments>http://shazwazza.com/post/Sharing-Controller-Actions-with-ControllerExtenders.aspx#comment</comments>
      <guid isPermaLink="false">http://shazwazza.com/post.aspx?id=2614a973-bbcb-4d26-b19f-d53c946fae98</guid>
      <pubDate>Tue, 04 Oct 2011 12:17:00 +1900</pubDate>
      <category>ASP.Net MVC</category>
      <dc:publisher>admin</dc:publisher>
      <pingback:server>http://shazwazza.com/pingback.axd</pingback:server>
      <pingback:target>http://shazwazza.com/post.aspx?id=2614a973-bbcb-4d26-b19f-d53c946fae98</pingback:target>
      <slash:comments>0</slash:comments>
      <trackback:ping>http://shazwazza.com/trackback.axd?id=2614a973-bbcb-4d26-b19f-d53c946fae98</trackback:ping>
      <wfw:comment>http://shazwazza.com/post/Sharing-Controller-Actions-with-ControllerExtenders.aspx#comment</wfw:comment>
      <wfw:commentRss>http://shazwazza.com/syndication.axd?post=2614a973-bbcb-4d26-b19f-d53c946fae98</wfw:commentRss>
    <feedburner:origLink>http://shazwazza.com/post.aspx?id=2614a973-bbcb-4d26-b19f-d53c946fae98</feedburner:origLink></item>
    <item>
      <title>Umbraco Jupiter Plugins - Part 4 - Editors</title>
      <description>&lt;p&gt;This is the fourth blog post in a series of posts relating to building plugins for Umbraco v5 (Jupiter). This post will show you how to &lt;strong&gt;get started &lt;/strong&gt;with building an editor. An Editor is the term used to express the editing pane on the right hand side of the back-office. Examples include: the content editor, media editor, document type editor, script editor, etc..&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Related Posts:&lt;/strong&gt;  &lt;ol&gt; &lt;li&gt;&lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-1.aspx"&gt;Umbraco Jupiter Plugins – Part 1&lt;/a&gt;  &lt;li&gt;&lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-2-Routing.aspx"&gt;Umbraco Jupiter Plugins – Part 2 – Routing&lt;/a&gt;  &lt;li&gt;&lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-3-Trees.aspx" target="_blank"&gt;Umbraco Jupiter Pluings – Part 3 – Trees&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt; &lt;h2&gt;Disclaimer&lt;/h2&gt; &lt;p&gt;&lt;em&gt;This post is about developing for Umbraco v5 (Jupiter) which at the time of this post is still under development. The technical details described below may change by the time Umbraco Jupiter is released. If you have feedback on the technical implementation details, please comment below.&lt;/em&gt;  &lt;h1&gt;Defining an Editor&lt;/h1&gt; &lt;p&gt;An Editor in Umbraco v5 is the combination of: An MVC Controller, View(s), JavaScript and CSS. The first step to creating an Editor is to create a class that inherits from the Umbraco base editor class: &lt;strong&gt;Umbraco.Cms.Web.Editors.StandardEditorController.&lt;/strong&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;The next step is to register this editor as an editor plugin. To do this you just need to add an attribute to your class such as:&lt;/p&gt;&lt;pre class="csharpcode"&gt;[Editor(&lt;span class="str"&gt;"ADD307B3-A5F9-4A89-ADAC-72289A5943FF"&lt;/span&gt;)]&lt;/pre&gt;
&lt;p&gt;The mandatory parameter passed to this attribute is the editor plugin ID (this MUST be unique so ensure you generated a new GUID for every single one of your plugins). 
&lt;p&gt;The next thing you’ll need to do to ensure your editor plugin is found and loaded is to ‘advertise’ that your assembly contains a plugin. To do this, just edit your assembly’s AssemblyInfo.cs file and add the following attribute:&lt;pre class="csharpcode"&gt;[assembly: AssemblyContainsPlugins]&lt;/pre&gt;
&lt;h1&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
Creating an Editor&lt;/h1&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Important convention: &lt;/strong&gt;All Editor controller names MUST be suffixed with ‘EditorController’. For example, if you are creating an editor to display system information, you might call your Editor: SystemInfo&lt;strong&gt;EditorController&lt;/strong&gt;. If you don’t follow this convention, you’re editor controller wont be routed.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;When creating an Editor there are a few base classes to choose from. Generally however, you should inherit from: &lt;strong&gt;Umbraco.Cms.Web.Editors.StandardEditorController&lt;/strong&gt;. The other base classes and their hierarchy are as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Umbraco.Cms.Web.Mvc.Controllers.BackOffice.SecuredBackOfficeController 
&lt;ul&gt;
&lt;li&gt;Umbraco.Cms.Web.Editors.BaseEditorController 
&lt;ul&gt;
&lt;li&gt;Umbraco.Cms.Web.Editors.DashboardEditorController 
&lt;ul&gt;
&lt;li&gt;Umbraco.Cms.Web.Editors.StandardEditorController&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;When inheriting from any of the base classes above, you will be required to create a constructor accepting an parameter of type: &lt;strong&gt;IBackOfficeRequestContext &lt;/strong&gt;:&lt;/p&gt;&lt;pre class="csharpcode"&gt;[Editor(&lt;span class="str"&gt;"ADD307B3-A5F9-4A89-ADAC-72289A5943FF"&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyEditorController : StandardEditorController
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; MyEditorController(IBackOfficeRequestContext requestContext)
        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(requestContext)
    {
    }        
}&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
The &lt;em&gt;StandardEditorController&lt;/em&gt; has an abstract method: &lt;em&gt;Edit(HiveId id)&lt;/em&gt; that needs to be implemented &lt;em&gt;(the abstract Edit Action is marked as [HttpGet])&lt;/em&gt;&lt;/p&gt;&lt;pre class="csharpcode"&gt;[Editor(&lt;span class="str"&gt;"ADD307B3-A5F9-4A89-ADAC-72289A5943FF"&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyEditorController : StandardEditorController
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; MyEditorController(IBackOfficeRequestContext requestContext)
        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(requestContext)
    {
    }
        
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; ActionResult Edit(HiveId id)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; View();
    }
}&lt;/pre&gt;
&lt;p&gt;Most Editors will be displaying a view to edit data based on a &lt;em&gt;HiveId &lt;/em&gt;which is the unique identifier type for pretty much all data in Umbraco 5. If you are writing an editor to edit data in a custom Hive provider, then this will work seamlessly for you. Even if you are creating an editor for data that you aren’t writing a custom Hive provider for, you can still use HiveId as a unique identifier since it has support for wrapping Guid, Int and String Id types. If however you decide that HiveId isn’t for you, then you can inherit from one of the other editor base classes that doesn’t have the abstract Edit method attached to it and create your own Actions with your own parameters.&lt;/p&gt;
&lt;p&gt;The above Edit Action simply returns a view without a model to be rendered. At this point, you’ll need to know where your view should be stored which has everything to do with MVC Areas or embedding views.&lt;/p&gt;
&lt;h1&gt;MVC Areas &amp;amp; Jupiter Packages&lt;/h1&gt;
&lt;p&gt;In a &lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-2-Routing.aspx" target="_blank"&gt;previous post&lt;/a&gt; we talk about how packages in v5 are actually registered as their own &lt;a href="http://msdn.microsoft.com/en-us/library/ee671793.aspx" target="_blank"&gt;MVC Area&lt;/a&gt;. All packages get installed to the following location: ~/App_Plugins/Packages/{YourPackageName} . If you aren’t embedding your views, then they should be stored inside of your package folder. Each plugin type has a specific view folder name that your views should be stored in:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Editor views &amp;amp; partial views: 
&lt;ul&gt;
&lt;li&gt;~/App_Plugins/Packages/{&lt;em&gt;YourPackageName&lt;/em&gt;}/&lt;strong&gt;Editors&lt;/strong&gt;/Views/ {&lt;em&gt;EditorControllerName&lt;/em&gt;}/{ViewName}.cshtml 
&lt;li&gt;~/App_Plugins/Packages/{&lt;em&gt;YourPackageName&lt;/em&gt;}/&lt;strong&gt;Editors&lt;/strong&gt;/Views/Shared/ {&lt;em&gt;ViewName&lt;/em&gt;}.cshtml&lt;/li&gt;&lt;/ul&gt;
&lt;li&gt;Property Editor partial views: 
&lt;ul&gt;
&lt;li&gt;~/App_Plugins/Packages/{&lt;em&gt;YourPackageName&lt;/em&gt;}/&lt;strong&gt;PropertyEditors&lt;/strong&gt;/Views/Shared/ {&lt;em&gt;ViewName&lt;/em&gt;}.cshtml&lt;/li&gt;&lt;/ul&gt;
&lt;li&gt;Dashboard partial views: 
&lt;ul&gt;
&lt;li&gt;~/App_Plugins/Packages/{&lt;em&gt;YourPackageName&lt;/em&gt;}/&lt;strong&gt;Dashboards&lt;/strong&gt;/Views/ {&lt;em&gt;ViewName&lt;/em&gt;}.cshtml&lt;/li&gt;&lt;/ul&gt;
&lt;li&gt;Rendering (front-end) partial views: 
&lt;ul&gt;
&lt;li&gt;~/App_Plugins/Packages/{&lt;em&gt;YourPackageName&lt;/em&gt;}/&lt;strong&gt;Views&lt;/strong&gt;/Partial/ {&lt;em&gt;ViewName&lt;/em&gt;}.cshtml&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;So with the controller created above, I would have a view in the following location:&lt;/p&gt;
&lt;p&gt;~/App_Plugins/{MyPackageName}/Editors/Views/MyEditor/Edit.cshtml&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: The package name folder will be created when installing your NuGet package and will be based on your NuGet package name and version assigned.&lt;/em&gt;&lt;/p&gt;
&lt;h1&gt;Embedding views&lt;/h1&gt;
&lt;p&gt;Many of the views shipped with v5 are embedded which helps to reduce the number of actual files that are shipped. This is also handy if you don’t want to give the ability for people to change what’s in your markup.&lt;/p&gt;
&lt;p&gt;Embedding a view is really easy:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Create a Razor (.cshtml) view in your Package’s project 
&lt;li&gt;View the Properties for this file and choose &lt;em&gt;‘Embedded Resource’&lt;/em&gt; as the ‘Build Action’&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;Now to use the embedded view we use the following syntax:&lt;/p&gt;&lt;pre class="csharpcode"&gt;[Editor(&lt;span class="str"&gt;"ADD307B3-A5F9-4A89-ADAC-72289A5943FF"&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyEditorController : StandardEditorController
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; MyEditorController(IBackOfficeRequestContext requestContext)
        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(requestContext)
    {
    }
        
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; ActionResult Edit(HiveId id)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; View(EmbeddedViewPath.Create(&lt;span class="str"&gt;"MyProject.Editors.Views.Edit.cshtml"&lt;/span&gt;));
    }
}&lt;/pre&gt;
&lt;p&gt;Its important to get the correct path to your view file. In this instance, my view’s path in my project is: &lt;em&gt;MyProject.Editors.Views.Edit.cshtml&lt;/em&gt;&lt;/p&gt;
&lt;h1&gt;Displaying your Editor&lt;/h1&gt;
&lt;p&gt;Most of the time an editor is displayed by clicking on a node in the tree or by accessing a context menu item. In a &lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-3-Trees.aspx" target="_blank"&gt;previous post&lt;/a&gt; about creating trees there was a method to create a tree node:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; UmbracoTreeResult GetTreeData(HiveEntityUri id, FormCollection queryStrings)
{
    NodeCollection.Add(
        CreateTreeNode(id, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="str"&gt;"My only node"&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty, &lt;span class="kwrd"&gt;false&lt;/span&gt;));
    &lt;span class="kwrd"&gt;return&lt;/span&gt; UmbracoTree();
}&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
This simply created a tree node that had no editor URL but now that we have an editor, I’ll update the code to click through to my Edit Action:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; UmbracoTreeResult GetTreeData(HiveId id, FormCollection queryStrings)
{
    NodeCollection.Add(
        CreateTreeNode(id, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="str"&gt;"My only node"&lt;/span&gt;,
        Url.GetEditorUrl(&lt;span class="str"&gt;"MyEditor"&lt;/span&gt;, id, &lt;span class="kwrd"&gt;new&lt;/span&gt; Guid(&lt;span class="str"&gt;"ADD307B3-A5F9-4A89-ADAC-72289A5943FF"&lt;/span&gt;)),
        &lt;span class="kwrd"&gt;false&lt;/span&gt;));
    &lt;span class="kwrd"&gt;return&lt;/span&gt; UmbracoTree();
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
GetEditorUrl is an extension method of UrlHelper which has a few overloads for generating an Editor’s Url. In this case we are passing in the Editor’s name and Id with the Id of the current node being rendered in the tree. 
&lt;p&gt;When the node is clicked it will now link to the Edit Action of the MyEditor Controller.&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Shazwazza/~3/hnOTwz1dTjU/post.aspx</link>
      <author>admin</author>
      <comments>http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-4-Editors.aspx#comment</comments>
      <guid isPermaLink="false">http://shazwazza.com/post.aspx?id=7171bc44-0a56-4234-b8d8-55b3998b9718</guid>
      <pubDate>Tue, 27 Sep 2011 05:56:38 +1900</pubDate>
      <category>Umbraco</category>
      <dc:publisher>admin</dc:publisher>
      <pingback:server>http://shazwazza.com/pingback.axd</pingback:server>
      <pingback:target>http://shazwazza.com/post.aspx?id=7171bc44-0a56-4234-b8d8-55b3998b9718</pingback:target>
      <slash:comments>7</slash:comments>
      <trackback:ping>http://shazwazza.com/trackback.axd?id=7171bc44-0a56-4234-b8d8-55b3998b9718</trackback:ping>
      <wfw:comment>http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-4-Editors.aspx#comment</wfw:comment>
      <wfw:commentRss>http://shazwazza.com/syndication.axd?post=7171bc44-0a56-4234-b8d8-55b3998b9718</wfw:commentRss>
    <feedburner:origLink>http://shazwazza.com/post.aspx?id=7171bc44-0a56-4234-b8d8-55b3998b9718</feedburner:origLink></item>
    <item>
      <title>Umbraco Jupiter Plugins - Part 3 - Trees</title>
      <description>&lt;p&gt;This is the third blog post in a series of posts relating to building plugins for Umbraco v5 (Jupiter).&amp;nbsp; This post will show you how to &lt;em&gt;get started &lt;/em&gt;with building a tree. A more in-depth example including rendering out child nodes, using many of the inbuilt helper/extension methods will come in a future blog, though in the meantime once you’ve read this post if you want to see more in-depth examples you can easily find them in our v5 source code.  &lt;p&gt;&lt;strong&gt;Related Posts:&lt;/strong&gt;  &lt;ol&gt; &lt;li&gt;&lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-1.aspx"&gt;Umbraco Jupiter Plugins – Part 1&lt;/a&gt;  &lt;li&gt;&lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-2-Routing.aspx" target="_blank"&gt;Umbraco Jupiter Plugins – Part 2 - Routing&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt; &lt;h2&gt;Disclaimer&lt;/h2&gt; &lt;p&gt;&lt;em&gt;This post is about developing for Umbraco v5 (Jupiter) which at the time of this post is still under development. The technical details described below may change by the time Umbraco Jupiter is released. If you have feedback on the technical implementation details, please comment below.&lt;/em&gt;&lt;/p&gt; &lt;h1&gt;Defining a tree&lt;/h1&gt; &lt;p&gt;A tree in &lt;a href="http://umbraco.com" target="_blank"&gt;Umbraco&lt;/a&gt; v5 is actually an &lt;a href="http://www.asp.net/mvc/tutorials/asp-net-mvc-controller-overview-cs" target="_blank"&gt;MVC Controller&lt;/a&gt; that returns JSON data. The first step to creating a tree is to create a class for your tree that inherits from the Umbraco base tree controller class: &lt;strong&gt;Umbraco.Cms.Web.Trees.TreeController&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;&lt;strong&gt;Important convention: &lt;/strong&gt;All Tree controller names MUST be suffixed with ‘TreeController’. For example, if you are creating a tree to display system information, you might call your Tree: SystemInfo&lt;strong&gt;TreeController&lt;/strong&gt;. If you don’t follow this convention, you’re tree controller wont be routed.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;The next step is to register this tree as a tree plugin. To do this you just need to add an attribute to your class such as:&lt;/p&gt;&lt;pre class="csharpcode"&gt;[Tree(&lt;span class="str"&gt;"A18108B1-9C86-4B47-AC04-A3089FE8D3EA"&lt;/span&gt;, &lt;span class="str"&gt;"My Custom Tree"&lt;/span&gt;)]&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
The two parameters passed to this attribute are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The tree plugin ID (this MUST be unique so ensure you generated a new GUID for every single one of your plugins) 
&lt;li&gt;The tree title. This will be the text rendered for the root node of your tree, however, this can be overridden and you could render out any title that you wish for your root node and it could even be dynamic. Also note that we will be supporting localization for the tree title.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The next thing you’ll need to do to ensure your tree plugin is found and loaded is to ‘advertise’ that your assembly contains a tree plugin. To do this, just edit your assembly’s AssemblyInfo.cs file and add the following attribute:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;strike&gt;&lt;span class="rem"&gt;//mark assembly for export as a tree plugin&lt;/span&gt;
[assembly: TreePluginAssembly]&lt;/strike&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
&lt;pre class="csharpcode"&gt;[assembly: AssemblyContainsPlugins]&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;h1&gt;Creating a tree&lt;/h1&gt;
&lt;h2&gt;Constructor&lt;/h2&gt;
&lt;p&gt;When inheriting from the base Umbraco.Cms.Web.Trees.TreeController, you will be required to create a constructor accepting an parameter of type: &lt;strong&gt;IBackOfficeRequestContext &lt;/strong&gt;:&lt;/p&gt;&lt;pre class="csharpcode"&gt;[Tree(&lt;span class="str"&gt;"A18108B1-9C86-4B47-AC04-A3089FE8D3EA"&lt;/span&gt;, &lt;span class="str"&gt;"My Custom Tree"&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MyTreeController : TreeController
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; MyTreeController(IBackOfficeRequestContext requestContext)
        : &lt;span class="kwrd"&gt;base&lt;/span&gt;(requestContext)
    {
    }

    &lt;span class="rem"&gt;//more code will go here....&lt;/span&gt;
    
}&lt;/pre&gt;
&lt;p&gt;The IBackOfficeRequestContext will most likely contain references to everything you’ll need to get the data for your tree. It includes references to: &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Hive 
&lt;li&gt;Umbraco settings 
&lt;li&gt;The TextManager (localization framework) 
&lt;li&gt;All of the registered plugins in the system 
&lt;li&gt;… and a whole lot more&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;However, you’ll be please to know that all plugins including Trees can take part in IoC contructor injection. So, if you want more objects injected into your tree controller you can just add the parameters to your constructor and they’ll be injected so long as they exist in the IoC container.&lt;/p&gt;
&lt;h2&gt;Overriding methods/properties&lt;/h2&gt;
&lt;p&gt;There is one property and one method you need to override:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;RootNodeId&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This property is just a getter and returns the root node id for your tree. Many trees exist at the absolute root of the data which is called the &lt;strong&gt;SystemRoot&lt;/strong&gt;. An example of a tree that exists at the system root would be trees like the: Data Type tree, Macro tree, Packages tree, tc… since they don’t have a heirarchy. Tree’s that have different start node Ids are trees like: Content, Media and Users.&amp;nbsp; Since each one of those entities share the same data structure, we separate these data structures under different start nodes from the SystemRoot.&lt;/p&gt;
&lt;p&gt;For the most part, if you are creating a utility type tree or a custom tree that doesn’t exist under a special hierarchy, the SystemRoot is what you’ll want:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; HiveEntityUri RootNodeId
{
    get { &lt;span class="kwrd"&gt;return&lt;/span&gt; FixedHiveIds.SystemRoot; }
}&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;GetTreeData&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This method is the method that returns the JSON tree data though to make it easy you don’t have to worry about JSON whatsoever. All you need to do is add &lt;strong&gt;TreeNode&lt;/strong&gt; objects to the existing &lt;strong&gt;NodeCollection&lt;/strong&gt; of the tree controller.&lt;/p&gt;
&lt;p&gt;As a very simple example, if you wanted to render out one node in your tree you could do this:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;protected&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; UmbracoTreeResult GetTreeData(HiveEntityUri id, FormCollection queryStrings)
{
    NodeCollection.Add(
        CreateTreeNode(id, &lt;span class="kwrd"&gt;null&lt;/span&gt;, &lt;span class="str"&gt;"My only node"&lt;/span&gt;, &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty, &lt;span class="kwrd"&gt;false&lt;/span&gt;));
    &lt;span class="kwrd"&gt;return&lt;/span&gt; UmbracoTree();
}&lt;/pre&gt;
&lt;p&gt;The &lt;strong&gt;CreateTreeNode&lt;/strong&gt; is a helper method which is part of the base &lt;strong&gt;TreeController &lt;/strong&gt;class that has many useful overloads. In this example, we’re giving it an id, not passing in any custom query string parameters, a title, not giving it an editor url and tagging the node as not having any children.&lt;/p&gt;
&lt;h1&gt;Registering a tree&lt;/h1&gt;
&lt;p&gt;In order to get your tree to show up in the back office, you need to register the tree in the config file: ~/App_Data/Umbraco/Config/umbraco.cms.trees.config , and here’s all you need to do to put it in the ‘settings’ app (as an example):&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;application&lt;/span&gt;&lt;span class="kwrd"&gt;="settings"&lt;/span&gt; 
     &lt;span class="attr"&gt;controllerType&lt;/span&gt;&lt;span class="kwrd"&gt;="MyProject.MyTreeController, MyProject"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;NOTE: At CodeGarden we discussed that you can ship your plugin inside a package and have your own config file deployed which Umbraco will recognize so that you don’t have to edit the already existing file…. This is still true! But we’ll write another blog post about that &lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://shazwazza.com/image.axd?picture=wlEmoticon-smile.png"&gt;&lt;/p&gt;
&lt;h1&gt;More in depth example?&lt;/h1&gt;
&lt;p&gt;As I mentioned at the start of this post I’ll write another one detailing our many extension and helper methods when rendering out trees, how to add menu items to your nodes, customize your icons, change the editor for particular nodes, etc… In the meantime though, please have a look at the v5 source code, the trees all exist in the project: &lt;strong&gt;Umbraco.Cms.Web.Trees&lt;/strong&gt;&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Shazwazza/~3/CcIzUS7uox0/post.aspx</link>
      <author>admin</author>
      <comments>http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-3-Trees.aspx#comment</comments>
      <guid isPermaLink="false">http://shazwazza.com/post.aspx?id=e508ef51-3c72-4cab-89c8-e67b06e853d2</guid>
      <pubDate>Sat, 20 Aug 2011 02:09:56 +1900</pubDate>
      <category>Umbraco</category>
      <dc:publisher>admin</dc:publisher>
      <pingback:server>http://shazwazza.com/pingback.axd</pingback:server>
      <pingback:target>http://shazwazza.com/post.aspx?id=e508ef51-3c72-4cab-89c8-e67b06e853d2</pingback:target>
      <slash:comments>14</slash:comments>
      <trackback:ping>http://shazwazza.com/trackback.axd?id=e508ef51-3c72-4cab-89c8-e67b06e853d2</trackback:ping>
      <wfw:comment>http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-3-Trees.aspx#comment</wfw:comment>
      <wfw:commentRss>http://shazwazza.com/syndication.axd?post=e508ef51-3c72-4cab-89c8-e67b06e853d2</wfw:commentRss>
    <feedburner:origLink>http://shazwazza.com/post.aspx?id=e508ef51-3c72-4cab-89c8-e67b06e853d2</feedburner:origLink></item>
    <item>
      <title>Partial View macros in Umbraco v5</title>
      <description>&lt;h2&gt;Disclaimer&lt;/h2&gt; &lt;p&gt;&lt;em&gt;This post is about developing for Umbraco v5 (Jupiter) which at the time of this post is still under development. The technical details described below may change by the time Umbraco Jupiter is released. If you have feedback on the technical implementation details, please comment below.&lt;/em&gt;  &lt;h1&gt;Macro Types&lt;/h1&gt; &lt;p&gt;In Umbraco v5, there are &lt;em&gt;currently&lt;/em&gt; 3 types of Macros:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Xslt  &lt;li&gt;Partial View  &lt;li&gt;Surface Action&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;The Xslt macro will remain very similar to the v4 Xslt macro, but the 2 other types are brand new. This post will cover the new &lt;strong&gt;Partial View Macro.&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;A Partial View in MVC is sort of synonymous with a User Control in WebForms. Its simply just a Razor view as a cshtml file. If you like Umbraco v4’s Razor macros, then you’ll be pleased to know that Razor is absolutely native to v5 and the Partial View Macro will be one of your best tools for working with v5.&lt;/p&gt; &lt;h1&gt;Creating a Partial View macro&lt;/h1&gt; &lt;p&gt;The first thing you’ll have to do is create the partial view, which you will need to save in the &lt;strong&gt;~/Views/Umbraco/Partial&lt;/strong&gt; folder. Next, a partial view macro needs to inherit from a custom view type, so the declaration at the top of your view will need to be:&lt;/p&gt;&lt;pre class="csharpcode"&gt;@inherits PartialViewMacro&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;Then, just like in v4, you’ll need to create a new macro in the &lt;em&gt;Developer&lt;/em&gt; section of the Umbraco back office. The &lt;em&gt;Macro Property&lt;/em&gt; interface looks very similar in v5:&lt;/p&gt;
&lt;p&gt;&lt;a href="http://shazwazza.com/image.axd?picture=image_32.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://shazwazza.com/image.axd?picture=image_thumb_30.png" width="421" height="356"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You’ll notice its slightly simplified as compared to v4. The 2nd drop down list dynamically changes based on the &lt;em&gt;Macro Type&lt;/em&gt; drop down list value.&lt;/p&gt;
&lt;p&gt;Once you’ve saved the macro, that’s it, your Macro is now created!&lt;/p&gt;
&lt;h1&gt;Using a Partial View macro&lt;/h1&gt;
&lt;p&gt;The razor syntax for rendering a macro in v5 is:&lt;/p&gt;&lt;pre class="csharpcode"&gt;@Html.UmbracoMacro(&lt;span class="str"&gt;"blah"&lt;/span&gt;)&lt;/pre&gt;
&lt;p&gt;As noted before, a Partial View Macro inherits from the view type: &lt;strong&gt;PartialViewMacro . &lt;/strong&gt;This view object contains a &lt;em&gt;Model&lt;/em&gt; property of type: &lt;strong&gt;Umbraco.Cms.Model.PartialViewMacroModel &lt;/strong&gt;which has a couple of properties you can use to render data to the page:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; Content CurrentNode { get; }
&lt;span class="kwrd"&gt;public&lt;/span&gt; dynamic MacroParameters { get; }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;The &lt;em&gt;CurrentNode&lt;/em&gt; property is very similar to v4’s currentPage parameter in Xslt. It will allow you to traverse the tree and render any content you like. Here’s &lt;em&gt;one&lt;/em&gt; way that you could list the child names from the current node:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;h2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Names of child nodes&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;h2&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
@foreach (var child in Model.CurrentNode.ChildContent().AsDynamic())
{
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;p&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        Child node name: &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;b&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;@child.Name&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;b&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;p&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
}&lt;/pre&gt;
&lt;h1&gt;Dynamic parameters&lt;/h1&gt;
&lt;p&gt;As you can see above, there’s a &lt;strong&gt;MacroParameters&lt;/strong&gt; property on the &lt;strong&gt;PartialViewMacroModel&lt;/strong&gt; which is a dynamic property just like MVC’s ViewBag. Passing data into the MacroParameters property can be done in your Macro declaration like so:&lt;/p&gt;&lt;pre class="csharpcode"&gt;@Html.UmbracoMacro(&lt;span class="str"&gt;"blah"&lt;/span&gt;, &lt;span class="kwrd"&gt;new&lt;/span&gt; { IsCool = &lt;span class="str"&gt;true&lt;/span&gt;, MyParameterName = &lt;span class="kwrd"&gt;new&lt;/span&gt; MyObject() })&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;This means that you can pass any type of object that you’d like into your macro with any parameter name. Then to use the parameters that you’ve passed in, you can reference them directly by name inside your macro:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;ul&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;@Model.MacroParameters.IsCool&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;@Model.MacroParameters.MyParameterName.ToString()&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;li&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ul&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;h1&gt;Macro parameters via the Macro Editor&lt;/h1&gt;
&lt;p&gt;A cool new feature in v5 is the new Macro parameter editor. It can now pre-populate all macro parameters found in Xslt, Partial Views and Surface controllers. Better still, is that the parameter editor has been completely rebuilt with Knockout JS so you can add/remove as many parameters as you like at once and then finally post your changes back when hitting save.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://shazwazza.com/image.axd?picture=image_33.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://shazwazza.com/image.axd?picture=image_thumb_31.png" width="475" height="275"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Oh, and another great feature in v5 is that the editors for macro parameters are actually just v5 &lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-1.aspx" target="_blank"&gt;Property Editors&lt;/a&gt; that are attributed as Macro Parameter Editors. &lt;/p&gt;
&lt;h1&gt;Strongly typed parameters&lt;/h1&gt;
&lt;p&gt;You may be wondering how the Macro Editor populates parameters from a Partial View Macro since we’ve seen that Partial View Macro model only supports dynamic (non stongly typed) properties… The answer is in Razor. Razor views allow you to define public properties, methods, etc… inside of the Razor markup. So if we want to have strongly typed parameters for our Partial View Macros which can be set based on Macro parameters in the rich text editor, all we have to do is declare them like:&lt;/p&gt;&lt;pre class="csharpcode"&gt;@inherits PartialViewMacro

@functions {

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsCool { get; set; }
    
}&lt;/pre&gt;
&lt;p&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
Now, the Partial View has a discoverable property which our Macro Editor will be able to see and automatically populate the parameter list. This property will also be set with any value that is selected in the Macro Parameter Editor when inserting one into the rich text box. Another thing to note is that if you are simply injecting parameter values using the &lt;strong&gt;Html.Macro &lt;/strong&gt;helper, then this property will be set so long as a dynamic property of the same name exists in the macro’s MacroParameter model properties.&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Shazwazza/~3/Dg-YQXtowkA/post.aspx</link>
      <author>admin</author>
      <comments>http://shazwazza.com/post/Partial-View-macros-in-Umbraco-v5.aspx#comment</comments>
      <guid isPermaLink="false">http://shazwazza.com/post.aspx?id=5d4d08e0-1103-4c0c-82d6-58b570f2cbc5</guid>
      <pubDate>Wed, 17 Aug 2011 16:00:00 +1900</pubDate>
      <category>Umbraco</category>
      <dc:publisher>admin</dc:publisher>
      <pingback:server>http://shazwazza.com/pingback.axd</pingback:server>
      <pingback:target>http://shazwazza.com/post.aspx?id=5d4d08e0-1103-4c0c-82d6-58b570f2cbc5</pingback:target>
      <slash:comments>12</slash:comments>
      <trackback:ping>http://shazwazza.com/trackback.axd?id=5d4d08e0-1103-4c0c-82d6-58b570f2cbc5</trackback:ping>
      <wfw:comment>http://shazwazza.com/post/Partial-View-macros-in-Umbraco-v5.aspx#comment</wfw:comment>
      <wfw:commentRss>http://shazwazza.com/syndication.axd?post=5d4d08e0-1103-4c0c-82d6-58b570f2cbc5</wfw:commentRss>
    <feedburner:origLink>http://shazwazza.com/post.aspx?id=5d4d08e0-1103-4c0c-82d6-58b570f2cbc5</feedburner:origLink></item>
    <item>
      <title>Sharing views between specific controllers</title>
      <description>&lt;p&gt;There’s no native way in MVC to share views between controllers without having to put those views in the ‘Shared’ folder which can be annoying especially if you have an inherited controller class structure, or your simply wish to just have one particular controller look for views in the folder of a different controller.&lt;/p&gt; &lt;p&gt;With a little help from &lt;a href="http://www.google.com.au/url?sa=t&amp;amp;source=web&amp;amp;cd=1&amp;amp;ved=0CB8QFjAA&amp;amp;url=http%3A%2F%2Fwww.jetbrains.com%2Fdecompiler%2F&amp;amp;ei=S28mTpqCEOKHmQWTrIzcCQ&amp;amp;usg=AFQjCNEHe70QThI6ntTvsyBhZHuW4K5F2A" target="_blank"&gt;DotPeek&lt;/a&gt; to see what’s going on inside of the &lt;em&gt;VirtualPathProviderViewEngine&lt;/em&gt;, I’ve created a fairly elegant solution to the above problem which consists of a custom ViewEngine and a custom controller Attribute. Lets start with the custom Attribute, its really simple and only contains one property which is the name of the controller that you wish the attributed controller to reference views.&amp;nbsp; An example:&lt;/p&gt;&lt;pre class="csharpcode"&gt;[AlternateViewEnginePath(&lt;span class="str"&gt;"ContentEditor"&lt;/span&gt;)]
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; MediaEditorController : Controller
{  ...  }&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;p&gt;The example above is saying that we have a MediaEditor controller that should reference views in the ContentEditor controller’s view folder, pretty simple right! A cool part about how the underlying ViewEngine works is that if a view isn’t found in the ContentEditor controller’s folder, then it will check back to the current controller’s folder, so it has built in fall back support.&lt;/p&gt;
&lt;p&gt;The custom ViewEngine is actually pretty simple as well once you know what’s going on inside of the &lt;em&gt;VirtualPathProviderViewEngine&lt;/em&gt;. There’s two particular methods: &lt;em&gt;FindView&lt;/em&gt; and &lt;em&gt;FindPartialView&lt;/em&gt; which the &lt;em&gt;VirtualPathProviderViewEngine&lt;/em&gt; figures out which controller/folder to look in. It figures this out by looking at the current ControllerContext’s RouteValues and simply does a lookup of the controller name by using this statement:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;controllerContext.RouteData.GetRequiredString("controller");&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So all we’ve got to do is override the &lt;em&gt;FindView&lt;/em&gt; and &lt;em&gt;FindPartialView&lt;/em&gt; methods, create a custom &lt;em&gt;ControllerContext&lt;/em&gt; with the “controller” route value to be the value specified in our custom attribute, and then pass this custom &lt;em&gt;ControllerContext&lt;/em&gt; into the underlying base &lt;em&gt;FindView&lt;/em&gt;/&lt;em&gt;FindPartial&lt;/em&gt; view methods:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// A ViewEngine that allows a controller's views to be shared with other &lt;/span&gt;
&lt;span class="rem"&gt;/// controllers without having to put these shared views in the 'Shared' folder.&lt;/span&gt;
&lt;span class="rem"&gt;/// This is useful for when you have inherited controllers.&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AlternateLocationViewEngine : RazorViewEngine
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; ViewEngineResult FindPartialView(
        ControllerContext controllerContext, 
        &lt;span class="kwrd"&gt;string&lt;/span&gt; partialViewName, 
        &lt;span class="kwrd"&gt;bool&lt;/span&gt; useCache)
    {
        var altContext = GetAlternateControllerContext(controllerContext);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (altContext != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            &lt;span class="rem"&gt;//see if we can get the view with the alternate controller &lt;/span&gt;
            &lt;span class="rem"&gt;//specified, if its found return the result, if its not found&lt;/span&gt;
            &lt;span class="rem"&gt;//then return the normal results which will try to find &lt;/span&gt;
            &lt;span class="rem"&gt;//the view based on the 'real' controllers name.&lt;/span&gt;
            var result = &lt;span class="kwrd"&gt;base&lt;/span&gt;.FindPartialView(altContext, partialViewName,useCache);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (result.View != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; result;
            }
        }
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;base&lt;/span&gt;.FindPartialView(controllerContext, partialViewName,useCache);
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; ViewEngineResult FindView(
        ControllerContext controllerContext, 
        &lt;span class="kwrd"&gt;string&lt;/span&gt; viewName, 
        &lt;span class="kwrd"&gt;string&lt;/span&gt; masterName, 
        &lt;span class="kwrd"&gt;bool&lt;/span&gt; useCache)
    {
        var altContext = GetAlternateControllerContext(controllerContext);
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (altContext!= &lt;span class="kwrd"&gt;null&lt;/span&gt;)
        {
            var result = &lt;span class="kwrd"&gt;base&lt;/span&gt;.FindView(altContext, viewName, masterName, useCache);
            &lt;span class="kwrd"&gt;if&lt;/span&gt; (result.View != &lt;span class="kwrd"&gt;null&lt;/span&gt;)
            {
                &lt;span class="kwrd"&gt;return&lt;/span&gt; result;
            }
        }
        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;base&lt;/span&gt;.FindView(controllerContext, viewName, masterName, useCache);
    }

    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// Returns a new controller context with the alternate controller name in the route values&lt;/span&gt;
    &lt;span class="rem"&gt;/// if the current controller is found to contain an AlternateViewEnginePathAttribute.&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;param name="currentContext"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
    &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; ControllerContext GetAlternateControllerContext(
        ControllerContext currentContext)
    {
        var controller = currentContext.Controller;
        var altControllerAttribute = controller.GetType()
            .GetCustomAttributes(&lt;span class="kwrd"&gt;typeof&lt;/span&gt;(AlternateViewEnginePathAttribute), &lt;span class="kwrd"&gt;false&lt;/span&gt;)
            .OfType&amp;lt;AlternateViewEnginePathAttribute&amp;gt;()
            .ToList();
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (altControllerAttribute.Any())
        {
            var altController = altControllerAttribute.Single().AlternateControllerName;
            &lt;span class="rem"&gt;//we're basically cloning the original route data here...&lt;/span&gt;
            var newRouteData = &lt;span class="kwrd"&gt;new&lt;/span&gt; RouteData
                {
                    Route = currentContext.RouteData.Route,
                    RouteHandler = currentContext.RouteData.RouteHandler
                };
            currentContext.RouteData.DataTokens
                .ForEach(x =&amp;gt; newRouteData.DataTokens.Add(x.Key, x.Value));
            currentContext.RouteData.Values
                .ForEach(x =&amp;gt; newRouteData.Values.Add(x.Key, x.Value));

            &lt;span class="rem"&gt;//now, update the new route data with the new alternate controller name&lt;/span&gt;
            newRouteData.Values[&lt;span class="str"&gt;"controller"&lt;/span&gt;] = altController;

            &lt;span class="rem"&gt;//now create a new controller context to pass to the view engine&lt;/span&gt;
            var newContext = &lt;span class="kwrd"&gt;new&lt;/span&gt; ControllerContext(
                currentContext.HttpContext, 
                newRouteData, 
                currentContext.Controller);
            &lt;span class="kwrd"&gt;return&lt;/span&gt; newContext;
        }

        &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;null&lt;/span&gt;;
    }
}

&lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// An attribute for a controller that specifies that the ViewEngine &lt;/span&gt;
&lt;span class="rem"&gt;/// should look for views for this controller using a different controllers name.&lt;/span&gt;
&lt;span class="rem"&gt;/// This is useful if you want to share views between specific controllers &lt;/span&gt;
&lt;span class="rem"&gt;/// but don't want to have to put all of the views into the Shared folder.&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; AlternateViewEnginePathAttribute : Attribute
{
    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; AlternateControllerName { get; set; }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; AlternateViewEnginePathAttribute(&lt;span class="kwrd"&gt;string&lt;/span&gt; altControllerName)
    {
        AlternateControllerName = altControllerName;
    }
}&lt;/pre&gt;
&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;

&lt;style type="text/css"&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/style&gt;
Lastly, you’ll need to just register this additional ViewEngine in your global.asax, or IoC, or however you are doing that sort of thing in your application.</description>
      <link>http://feedproxy.google.com/~r/Shazwazza/~3/A2TF96-IPFk/post.aspx</link>
      <author>admin</author>
      <comments>http://shazwazza.com/post/Sharing-views-between-specific-controllers.aspx#comment</comments>
      <guid isPermaLink="false">http://shazwazza.com/post.aspx?id=57af4388-6d25-4f88-82d1-f8174987c800</guid>
      <pubDate>Thu, 21 Jul 2011 01:29:23 +1900</pubDate>
      <category>ASP.Net MVC</category>
      <dc:publisher>admin</dc:publisher>
      <pingback:server>http://shazwazza.com/pingback.axd</pingback:server>
      <pingback:target>http://shazwazza.com/post.aspx?id=57af4388-6d25-4f88-82d1-f8174987c800</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://shazwazza.com/trackback.axd?id=57af4388-6d25-4f88-82d1-f8174987c800</trackback:ping>
      <wfw:comment>http://shazwazza.com/post/Sharing-views-between-specific-controllers.aspx#comment</wfw:comment>
      <wfw:commentRss>http://shazwazza.com/syndication.axd?post=57af4388-6d25-4f88-82d1-f8174987c800</wfw:commentRss>
    <feedburner:origLink>http://shazwazza.com/post.aspx?id=57af4388-6d25-4f88-82d1-f8174987c800</feedburner:origLink></item>
    <item>
      <title>Umbraco Jupiter Plugins - Part 2 - Routing</title>
      <description>&lt;p&gt;This is the second blog post in a series of posts relating to building plugins for Umbraco v5 (Jupiter). &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Related Posts:&lt;/strong&gt;&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-1.aspx"&gt;Umbraco Jupiter Plugins – Part 1&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;h2&gt;Disclaimer&lt;/h2&gt;  &lt;p&gt;&lt;em&gt;This post is about developing for Umbraco v5 (Jupiter) which at the time of this post is still under development. The technical details described below may change by the time Umbraco Jupiter is released. If you have feedback on the technical implementation details, please comment below.&lt;/em&gt;&lt;/p&gt;  &lt;h1&gt;Routing &amp;amp; URLs&lt;/h1&gt;  &lt;p&gt;As mentioned in the &lt;a href="http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-1.aspx"&gt;previous post&lt;/a&gt; Umbraco Jupiter will consist of many types of plugins, and of those plugins many of them exist as &lt;a href="http://www.asp.net/mvc/tutorials/asp-net-mvc-controller-overview-cs" target="_blank"&gt;MVC Controllers&lt;/a&gt;.&amp;#160; Each controller has an Action which a URL is routed to, this means that each Controller plugin in Jupiter requires it’s own unique URLs. The good news is that you as a package developer need not worry about managing these URLs and routes, Jupiter will conveniently do all of this for you. &lt;/p&gt;  &lt;h1&gt;Packages &amp;amp; Areas&lt;/h1&gt;  &lt;p&gt;My previous post mentioned that a ‘Package’ in Jupiter is a collection of ‘Plugins’ and as it turns out, Plugins can’t really function unless they are part of a Package. In it’s simplest form, a Package in v5 is a folder which contains Plugins that exists in the &lt;strong&gt;~/Plugins/Packages&lt;/strong&gt; sub folder. The folder name of the package becomes very important because it is used in setting up the routes to&amp;#160; create the unique URLs which map to the MVC Controller plugins. Package developers should be aware that they should name their folder to something that is reasonably unique so it doesn’t overlap with other Package folder names. During package installation, Jupiter will check for uniqueness in Package folder names to ensure there is no overlap (&lt;em&gt;there will be an entirely separate post on how to create deployment packages and how to install them&lt;/em&gt;).&lt;/p&gt;  &lt;p&gt;Here’s a quick example: If I have a Package that contains a &lt;em&gt;Tree &lt;/em&gt;plugin called &lt;em&gt;TestTree&lt;/em&gt; (which is in fact an MVC Controller) and I’ve called my Package folder ‘&lt;em&gt;Shazwazza’&lt;/em&gt;, which exists at &lt;strong&gt;~/Plugins/Packages/Shazwazza &lt;/strong&gt;then the URL to return the JSON for the tree is: &lt;a href="http://localhost/Umbraco/Shazwazza/Trees/TestTree/Index"&gt;http://localhost/Umbraco/Shazwazza/Trees/TestTree/Index&lt;/a&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Similarly, if I have a &lt;em&gt;Editor&lt;/em&gt; plugin called &lt;em&gt;TestEditor &lt;/em&gt;with an action called &lt;em&gt;Edit&lt;/em&gt;, then a URL to render the Edit Action is:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://localhost/Umbraco/Shazwazza/Editors/TestEditor/Edit"&gt;http://localhost/Umbraco/Shazwazza/Editors/TestEditor/Edit&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;If you’ve worked with MVC, you’ll probably know what an &lt;a href="http://msdn.microsoft.com/en-us/library/ee671793.aspx" target="_blank"&gt;MVC Area&lt;/a&gt; is. The way that Jupiter creates the routes for Packages/Plugins is by creating an MVC Area for each Package. This is how it deals with the probability that different Package developers may create MVC Controllers with the same name. MVC routes are generally based just on a Controller name and an Action name which wouldn’t really work for us because there’s bound to be overlap amongst Package developers, so by creating an Area for each Package the route becomes unique to a combination of Controller name, Action name and Area name.&amp;#160; MVC also determines where to look for Views based on Area name which solves another issue of multiple Packages installed with the same View names.&lt;/p&gt;  &lt;h1&gt;Whats next?&lt;/h1&gt;  &lt;p&gt;In the coming blog posts I’ll talk about &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;how plugins are installed and loaded &lt;/li&gt;    &lt;li&gt;how and where the Views are stored that the plugins reference &lt;/li&gt;    &lt;li&gt;how to create all of the different types of plugins &lt;/li&gt; &lt;/ul&gt;  &lt;h1&gt;Code Garden 2011&lt;/h1&gt;  &lt;p&gt;I’ll be doing a talk on &lt;a href="http://codegarden11.com/sessions/day-2/slot-one/get-plugged-in-to-umbraco-jupiter.aspx" target="_blank"&gt;Plugins for Umbraco Jupiter&lt;/a&gt; at &lt;a href="http://codegarden11.com/" target="_blank"&gt;Code Garden 2011&lt;/a&gt; this year which will go in to a lot more detail than these blog posts. If you are attending Code Garden already, then hopefully this series will give you a head start on Umbraco v5. If you haven’t got your tickets to Code Garden yet, what are you waiting for?! We have so much information to share with you :)&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Shazwazza/~3/hL6e_NOCYOc/post.aspx</link>
      <author>admin</author>
      <comments>http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-2-Routing.aspx#comment</comments>
      <guid isPermaLink="false">http://shazwazza.com/post.aspx?id=3665667d-7a21-4eaf-9dab-f97c7062c507</guid>
      <pubDate>Wed, 11 May 2011 08:26:14 +1900</pubDate>
      <category>Umbraco</category>
      <category>ASP.Net MVC</category>
      <dc:publisher>admin</dc:publisher>
      <pingback:server>http://shazwazza.com/pingback.axd</pingback:server>
      <pingback:target>http://shazwazza.com/post.aspx?id=3665667d-7a21-4eaf-9dab-f97c7062c507</pingback:target>
      <slash:comments>2</slash:comments>
      <trackback:ping>http://shazwazza.com/trackback.axd?id=3665667d-7a21-4eaf-9dab-f97c7062c507</trackback:ping>
      <wfw:comment>http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-2-Routing.aspx#comment</wfw:comment>
      <wfw:commentRss>http://shazwazza.com/syndication.axd?post=3665667d-7a21-4eaf-9dab-f97c7062c507</wfw:commentRss>
    <feedburner:origLink>http://shazwazza.com/post.aspx?id=3665667d-7a21-4eaf-9dab-f97c7062c507</feedburner:origLink></item>
    <item>
      <title>Umbraco Jupiter Plugins - Part 1</title>
      <description>&lt;p&gt;This is the first blog post in a series of posts relating to building plugins for Umbraco v5 (Jupiter)&lt;/p&gt;  &lt;h2&gt;Disclaimer&lt;/h2&gt;  &lt;p&gt;&lt;em&gt;This post is about developing for Umbraco v5 (Jupiter) which at the time of this post is still under development. The technical details described below may change by the time Umbraco Jupiter is released. If you have feedback on the technical implementation details, please comment below.&lt;/em&gt;&lt;/p&gt;  &lt;h1&gt;What is a plugin&lt;/h1&gt;  &lt;p&gt;Since Umbraco Jupiter has been built from the ground up, we first need to define some v5 terminology:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Plugin&lt;/strong&gt; = A single functional component that extends Umbraco such as a Tree, an Editor, a Menu Item, etc… &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Package&lt;/strong&gt; = A group of Plugins installed into Umbraco via the ~/Plugins/Packages/&lt;em&gt;[Package Name]&lt;/em&gt; folder &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The Umbraco v5 back-office has been architected to run entirely on Plugins, in fact the core trees, editors, etc… that are shipped with Umbraco are Plugins in v5.&lt;/p&gt;  &lt;h1&gt;Types of plugins&lt;/h1&gt;  &lt;p&gt;The list of Plugin types will most likely increase from the time of this blog post to when Jupiter is launched but as it stands now here are the types of Plugins supported in v5:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;strong&gt;Property Editors &lt;/strong&gt;      &lt;ul&gt;       &lt;li&gt;This term is new to v5. In v4.x there was no differentiation between a &lt;em&gt;Data Type&lt;/em&gt; and it’s underlying ‘Data Type’ editor. In v5 we’ve made a clear distinction between a ‘Data Type’ (as seen in the &lt;em&gt;Data Type&lt;/em&gt; tree and used as properties for &lt;em&gt;Document Types&lt;/em&gt;) and the underlying editor and pre-value editor that it exposes.&amp;#160; An example of a &lt;em&gt;Property Editor&lt;/em&gt; would be &lt;a href="http://ucomponents.codeplex.com" target="_blank"&gt;uComponents’&lt;/a&gt; Multi-Node Tree Picker. An example of a &lt;em&gt;Data Type&lt;/em&gt; would be when an Umbraco administrator creates a new &lt;em&gt;Data Type &lt;/em&gt;node in the &lt;em&gt;Data Type &lt;/em&gt;tree and assigns the Multi-Node Tree Picker as it’s &lt;em&gt;Property Editor&lt;/em&gt;. &lt;/li&gt;        &lt;li&gt;So uComponents Team, this is where you need to focus your efforts for version 5! &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Menu Items&lt;/strong&gt;       &lt;ul&gt;       &lt;li&gt;Context menu items such as Create, Publish, Audit Trail, etc… are all plugins. &lt;/li&gt;        &lt;li&gt;See &lt;a href="http://shazwazza.com/post/Custom-Actions-in-Umbraco-Jupiter.aspx" target="_blank"&gt;this post&lt;/a&gt; in regards to creating menu items in v5, though there have been some new features added since that article was created which I’ll detail in coming posts in this series. &lt;!--EndFragment--&gt;&lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Editors&lt;/strong&gt;       &lt;ul&gt;       &lt;li&gt;Editor plugins are all of the interactions performed in the right hand editor panel and in modal dialogs in the back-office. &lt;/li&gt;        &lt;li&gt;For example, the Content Editor core plugin in v5 manages the rendering for all views such as editing content, sorting, copying, and moving nodes, and nearly all of the other views that the context menu actions render. &lt;/li&gt;        &lt;li&gt;Editors are comprised mostly of MVC Controllers, Views, JavaScript &amp;amp; CSS. &lt;!--EndFragment--&gt;&lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Trees&lt;/strong&gt;       &lt;ul&gt;       &lt;li&gt;All trees are plugins, for example, the Content tree, Media tree, Document Type tree are all different plugins. &lt;/li&gt;        &lt;li&gt;Trees are actually MVC controllers. &lt;/li&gt;        &lt;li&gt;Tree nodes use &lt;em&gt;Menu Items&lt;/em&gt; to render &lt;em&gt;Editors&lt;/em&gt; &lt;/li&gt;     &lt;/ul&gt;   &lt;/li&gt;    &lt;li&gt;&amp;#160;&lt;strong&gt;Presentation Addins (Yet to be officially named)&lt;/strong&gt; &lt;/li&gt;    &lt;ul&gt;     &lt;li&gt;Another type of plugin are Controllers that are installed via packages that interact with the presentation layer, an example of this might be the Controller Action that accepts the post values from a Contour form. &lt;/li&gt;   &lt;/ul&gt; &lt;/ul&gt;  &lt;h1&gt;Whats next?&lt;/h1&gt;  &lt;p&gt;In the coming blog posts I’ll talk about &lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;how plugins are installed and loaded &lt;/li&gt;    &lt;li&gt;how the Umbraco routing system works with all of these controllers &lt;/li&gt;    &lt;li&gt;how and where the Views are stored that the plugins reference &lt;/li&gt;    &lt;li&gt;how to create all of the different types of plugins &lt;/li&gt; &lt;/ul&gt;  &lt;h1&gt;Code Garden 2011&lt;/h1&gt;  &lt;p&gt;I’ll be doing a talk on &lt;a href="http://codegarden11.com/sessions/day-2/slot-one/get-plugged-in-to-umbraco-jupiter.aspx" target="_blank"&gt;Plugins for Umbraco Jupiter&lt;/a&gt; at &lt;a href="http://codegarden11.com/" target="_blank"&gt;Code Garden 2011&lt;/a&gt; this year which will go in to a lot more detail than these blog posts. If you are attending Code Garden already, then hopefully this series will give you a head start on Umbraco v5. If you haven’t got your tickets to Code Garden yet, what are you waiting for?! We have so much information to share with you :)&lt;/p&gt;</description>
      <link>http://feedproxy.google.com/~r/Shazwazza/~3/v3qLQX0GnPI/post.aspx</link>
      <author>admin</author>
      <comments>http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-1.aspx#comment</comments>
      <guid isPermaLink="false">http://shazwazza.com/post.aspx?id=6a5def43-7ed7-4983-9ee1-4a73fd654050</guid>
      <pubDate>Fri, 29 Apr 2011 09:55:14 +1900</pubDate>
      <category>ASP.Net MVC</category>
      <category>Umbraco</category>
      <dc:publisher>admin</dc:publisher>
      <pingback:server>http://shazwazza.com/pingback.axd</pingback:server>
      <pingback:target>http://shazwazza.com/post.aspx?id=6a5def43-7ed7-4983-9ee1-4a73fd654050</pingback:target>
      <slash:comments>10</slash:comments>
      <trackback:ping>http://shazwazza.com/trackback.axd?id=6a5def43-7ed7-4983-9ee1-4a73fd654050</trackback:ping>
      <wfw:comment>http://shazwazza.com/post/Umbraco-Jupiter-Plugins-Part-1.aspx#comment</wfw:comment>
      <wfw:commentRss>http://shazwazza.com/syndication.axd?post=6a5def43-7ed7-4983-9ee1-4a73fd654050</wfw:commentRss>
    <feedburner:origLink>http://shazwazza.com/post.aspx?id=6a5def43-7ed7-4983-9ee1-4a73fd654050</feedburner:origLink></item>
  </channel>
</rss>

