当我使用Razor Engine评估模板并只想打印If语句中包含的整个块时,是否真的必须用“ @:”标记每一行:
@if(Model.Labels)
{
@:arcs.append("text")
@:.attr("transform", function (d) {
@:var c = arc.centroid(d),
@:x = c[0],
@:y = c[1],
@:// pythagorean theorem for hypotenuse
@:h = Math.sqrt(x * x + y * y);
@:return "translate(" + (x / h * labelr) + ',' +
@:(y / h * labelr) + ")";
@:})
@:.attr("dy", ".35em")
@:.attr("text-anchor", function (d) {
@:// are we past the center?
@:return (d.endAngle + d.startAngle) / 2 > Math.PI ?
@:"end" : "start";
@:})
@:.text(function (d) { return d.data.name; });
}
else
{
}
您可以在此处查看有关Razor语法的精彩文章:http : //weblogs.asp.net/scottgu/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax
简而言之,此处应用的规则是:
您有一个代码块-“ if”-并且在其中,除非有以下情况,否则代码是预期的:
<text></text>
标签。这样,text
标记内的内容将按您放置的方式呈现,而不会在其周围添加任何标记或文本,因此对于您的JavaScript代码,它将呈现您指定的代码。@:
lexeme,它告诉razor将其后的内容视为html / text。简而言之,将您的代码更改为此代码是您所需要的:
@if(Model.Labels)
{
<text>
arcs.append("text")
.attr("transform", function (d) {
var c = arc.centroid(d),
x = c[0],
y = c[1],
// pythagorean theorem for hypotenuse
h = Math.sqrt(x * x + y * y);
return "translate(" + (x / h * labelr) + ',' +
(y / h * labelr) + ")";
})
.attr("dy", ".35em")
.attr("text-anchor", function (d) {
// are we past the center?
return (d.endAngle + d.startAngle) / 2 > Math.PI ?
"end" : "start";
})
.text(function (d) { return d.data.name; });
</text>
}
else
{
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句