4

Using ServiceStack Markdown Razor, how can I create an HtmlHelper extension method that works like:

In your views you can now do:

@{
    using (Html.BeginLink())
    { 
        @Html.Raw("Hello World")
    }
}

Which yields the result:

<a>Hello World</a>

from This StackOverflow Answer

ServiceStack Markdown Razor has no concept of ViewContext, so I'm unsure how I'd get a Writer the same way as in the SO Answer.


UPDATE

I can get at the ViewPage's StringBuilder directly from:

@{ this.ViewPage.Builder }

But is this the intended way to access it? If it was intended to directly access the StringBuilder, wouldn't the StringBuilder be exposed from the HtmlHelper in lieu of ViewData (from MVC)?

Community
  • 1
  • 1
Tyst
  • 861
  • 1
  • 11
  • 26

1 Answers1

2

You could do something like:

public static class MyHelpers
{

    public static IHtmlString PrintHelloWorld(this HtmlHelper helper)
    {
        return helper.Raw("Hello World");
    }
}

Just make sure that the class above is in the same namespace as the HtmlHelper.

b_meyer
  • 594
  • 2
  • 7