我可以返回使用剃刀的@helper语法的字符串? [英] Can I return a string using the @helper syntax in Razor?

查看:95
本文介绍了我可以返回使用剃刀的@helper语法的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 APP_ code A RazorHelpers.cshtml文件,该文件是这样的:

I have a RazorHelpers.cshtml file in app_code which looks like:

@using Molecular.AdidasCoach.Library.GlobalConstants

@helper Translate(string key)
{
    @GlobalConfigs.GetTranslatedValue(key)
}

不过,我有我想要使用结果作为链接文本的情况下的 @ Html.ActionLink(...)。我不能结果转换为字符串。

However, I have a case where I want to use the result as the link text in an @Html.ActionLink(...). I cannot cast the result to a string.

有没有办法从剃刀助手返回纯字符串,这样我既可以在HTML和 @Html 助手中使用它们?

Is there any way to return plain strings from Razor helpers so that I can use them both in HTML and within an @Html helper?

推荐答案

剃刀助手返回 HelperResult 的对象。

您可以通过调用的ToString()

有关更多信息,请参见我的博客文章

For more information, see my blog post.

这篇关于我可以返回使用剃刀的@helper语法的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆