标记铸件仍在编码字符串
我发现了许多如何使用MarkupString的示例,而它只是不做应该的事情。
在我的大火组件中,
<small class="help-text editable-label" @ref="HelpText">
@(!string.IsNullOrWhiteSpace(Model.HelpText) ? (MarkupString)Model.HelpText : "Double-click here to add text")
</small>
我现在有一个简单的模型,在该模型中,我将Helptext初始化到
"<b><i>This is a test</b></i>"
我的网页中,我可以显示出精确的输出。 (请参阅附件)。
I've found numerous examples of how to use MarkupString and it's just not doing what it's supposed to.
In my blazor component I have:
<small class="help-text editable-label" @ref="HelpText">
@(!string.IsNullOrWhiteSpace(Model.HelpText) ? (MarkupString)Model.HelpText : "Double-click here to add text")
</small>
I have a simple model right now where I initialize HelpText to
"<b><i>This is a test</b></i>"
In my webpage I get that exact output displayed. (See attached picture).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这实际上是对
的变化?:
的变化。以某种方式将标记标记值转换为对象?
,然后再次转换为String
。老实说,我感到惊讶的是您的代码编译,
的两个分支?:
必须是'sigsment兼容',并且不能将标记串分配给字符串。您可以做到这一点:
但是,这变得如此丑陋,我会将其移至@Code部分。
This is actually do to the vagaries of
?:
. Somehow the MarkupString value is converted toobject?
and then tostring
again.To be honest I was surprised your code compiles, the two branches of
?:
must be 'assignment compatible', and MarkupString cannot be assigned to string.You can do this:
but that is getting so ugly I would move it to the @code section.