内联助手和页面输出-怎么样? [英] Inline helpers and page output - how?
问题描述
我有一个HtmlHelper函数,该函数返回一个MvcHtmlString
,并且我想在这样的内联帮助器中调用它:
I have an HtmlHelper function that returns a MvcHtmlString
and which I'd like to call in an inline helper like this:
@helper JsCss()
{
Html.Script("jquery/jquery-1.6.2", cdn: true)
}
我从页面上调用内联帮助器:
I call the inline helper from my page:
<head>
@JsCss()
</head>
...问题是:页面上什么都没有显示!看来我必须这样做:
...trouble is: nothing shows up on the page! it seems I have to do this:
@helper JsCss()
{
<text>
@Html.Script("jquery/jquery-1.6.2", cdn: true)
</text>
}
所以我想事情是我必须打印" Html.Script
调用返回到页面的值...我还能怎么做?
so I guess the thing is I have to "print" the return value of my Html.Script
call to the page... how else could I do this?
推荐答案
帮助程序是一个代码块,您需要在Html.Script
之前加上@
前缀,以便Razor知道要输出返回值(您不会不需要<text></text>
):
A helper is a code block, you need to prefix the Html.Script
with @
so Razor knows you want to output the return value (you don't need the <text></text>
):
@helper JsCss()
{
@Html.Script("jquery/jquery-1.6.2", cdn: true)
}
这篇关于内联助手和页面输出-怎么样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!