Can I return a string using the @helper syntax in Razor?

Razor helpers return HelperResult objects.

You can get the raw HTML by calling ToString().

For more information, see my blog post.


I don't think there is a way to make @helper return other types than HelperResult. But you could use a function with a return type of string, e.g.

@functions {
    public static string tr(string key) {
        return GlobalConfigs.GetTranslatedValue(key);
    }
}

then

@Html.ActionLink(tr("KEY"), "action", "controller")

See also http://www.mikesdotnetting.com/article/173/the-difference-between-helpers-and-functions-in-webmatrix

edit: MVC Razor: Helper result in html.actionlink suggests your helper can return a string by using @Html.Raw(GlobalConfigs.GetTranslatedValue(key));