ASP.NET MVC 3使用剃须刀 - 一起使用条件前pression与HTML输出 [英] ASP.NET MVC 3 using Razor - use conditional expression together with the HTML output
问题描述
我一直在窃听这个很多天......(我在学习ASP.NET MVC 3的过程)
在这个链接 - 剃须刀的if / else条件运算符语法 - - 有消息称,在剃刀引擎有条件的前pression唯一有效的语法是@(?X Y:Z)
好吧。现在,我怎么写HTML在这种条件前pression?我不能在这里使用剃刀,继无效的语法错误code的结果。
@(item.Manager == NULL @:< I>未分配的< / I>:item.Manager.Name)
经过一番研究,我发现的HTMLWriter或Html.Raw但都没有,也没有他们的方法的ToString()或.toHtmlString()的帮助,因为它们不是字符串,但IHtmlString类型。
感谢您的答复!
@(item.Manager == NULL新HtmlString(?< I>未分配的< /我>中)新HtmlString(item.Manager.Name))
I've been bugged with this for many days...(I'm in process of studying ASP.NET MVC 3)
In this link -- Razor If/Else conditional operator syntax -- is said that the only valid syntax for conditional expression in Razor engine is @(x?y:z)
Alright. Now, how do I write HTML in this conditional expression? I can't use Razor here, following code results in invalid syntax error.
@(item.Manager == null ? @:<i>unassigned</i> : item.Manager.Name)
After some research I discovered HtmlWriter or Html.Raw but neither of them, nor their methods .toString() or .toHtmlString() help because they are not of string but of IHtmlString type.
Thanks for reply!
@(item.Manager == null ? new HtmlString("<i>unassigned</i>") : new HtmlString( item.Manager.Name) )
这篇关于ASP.NET MVC 3使用剃须刀 - 一起使用条件前pression与HTML输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!