逐字字符串文字不解释 html

在我的控制器操作中,我正在向视图发送消息 -


model.Result = ex.Message;

model.Result = model.Result + @" If you would like to create one, please <a href="something"> click here </a>";

所以,我希望消息像这样显示 -


The member doesn't exist. If you would like to create one, please click here.

但实际显示的是


The member doesn't exist. If you would like to create one, please <a href> click here </a>.

所以,我有两个问题——


1) 为什么逐字字符串文字不评估 html。


2)有没有更好的方法来做到这一点?我不喜欢在我的控制器中使用 html,但我也不想为一行 html 过度构建东西。


烙印99
浏览 200回答 1
1回答

小唯快跑啊

Razor 自动对字符串进行 HTML 编码以确保安全(以防止脚本注入)。Html.Raw如果您想要实际的 HTML,则需要使用。@Html.Raw(Model.ResultMessage)
打开App,查看更多内容
随时随地看视频慕课网APP