本文介绍了有没有一种方法来终止MVC剃刀@:行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 考虑这个例子:<input type="checkbox" @if (flag) { @: checked } />问题是,} /方式&gt; 被剃刀引擎视为输出字符串的一部分The problem is that the } /> is conceived by the Razor engine as part of the output string.我试图用括号但没有运气。I've tried to use parenthesis but no luck.有没有办法来终止 @:在同一行运营商,不然我就必须把它拆分到其它线路/使用三元运算符Is there a way to terminate the @: operator in same line, or I'll have to split it to other line / use ternary operator?我的要求的一个非常普遍的用例可以添加类,如果值是true:A very common use-case of my request can be adding a class if a value is true:<div class='container @(active ? "active")'/>因此,如果:三元运营商是不是present,它把它把它当作一元如果运营商,但是这只是一个愿望...So if the : of the ternary operator isn't present, it treats it treats it as a unary if operator, but that's just a wish... 在这里是我对C#UserVoice的建议。Here's my suggestion on C# UserVoice.推荐答案有关,您可以使用 @value 语法,也有复选框特殊情况(见单个属性剃刀快速参考):For single attribute you can use @value syntax, that also have special case for checkbox (see Razor quick reference ):<input type="checkbox" checked="@flag" />您也可以使用&LT;文本&GT; 语法,提供了明确的(而不是将结束行)结束标记:You also can use <text> syntax that provides explicit (instead of "up to end of the line") closing tag:<input type="checkbox" @if (flag) { <text>checked</text> } /> 这篇关于有没有一种方法来终止MVC剃刀@:行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-26 06:50