Method Rendering

Today I’ll show how to use Method Rendering. This rendering type outputs the return value of a call to a static method.
Item of method rendering contains three fields which should be filled:
Parameters field I use as a output.method rendering

Now we have to create Methods class within MethodRenderingDemo library with SayHello static method which return string.

namespace MethodRenderingDemo
    using Sitecore.Mvc.Presentation;

    public class Methods
        public static string SayHello()
            return RenderingContext.Current.Rendering.RenderingItem.Parameters;

This line of code returns value of Parameters field. In this case it is ‘hello from method rendering’.


So after you place method rendering on layout you will see such output:
method rendering output

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s