【发布时间】:2012-05-13 19:34:27
【问题描述】:
我的用例是我有一个 html 模板,我希望编译服务器端,但在 RAZOR 视图中定义。
无法使用 RAZOR 语法渲染此模板,因为该值仅存在于客户端。像jQuery模板之类的。
理想情况下,它会从 tje 视图中传入:
@Html.Template(<this somehow indicates it's the start of my string>
<div>Hello {{= NameOfHomePlanet }}</div>
<div>And welcome to a second line!</div>
</this somehow indicates it's the end of my string>);
现在在助手中:
public static Template(this Html html, string template)
{
// tmplate == " <div>Hello {{= NameOfHomePlanet }}</div>\n"
// + "<div>And welcome to a second line!</div>";
}
这将导致最外层虚构标签之间的 HTML 作为名为 Template 的 Html 帮助器的第一个参数传入。
在玩的过程中,我无法弄清楚语法。这可能吗?
【问题讨论】:
-
HTML 有预定义的结构?我建议您为每次需要使用不同的 HtmlHelper。比方说,一个用于处理“PlanetWelcome”的 HtmlHelper,您将“NameOfHomePlanet”和任何其他信息作为参数传递。
标签: c# asp.net-mvc-3 razor html-helper