[英]How to run Html and Url helpers when use Html.Raw - ASP NET MVC
I'm trying to get some html part from database, and when i use Html.Raw(htmlString)
helpers render as string instead of execute it.我正在尝试从数据库中获取一些 html 部分,并且当我使用
Html.Raw(htmlString)
助手呈现为字符串而不是执行它时。
Exemple:示例:
@{
var html = "<img src=\"@Url.Asset(\"img/banner-example.png\")\">";
}
@Html.Raw(html);
And that render而那个渲染
<img src="@Url.Asset("img/banner-exemple.png")">
How can i do that?我怎样才能做到这一点?
It's more complicated to expect the engine to run the code in Raw output.期望引擎运行 Raw output 中的代码更为复杂。 Instead just create the string you're looking for.
相反,只需创建您正在寻找的字符串。
@{
var html = "<img src=\"" + Url.Asset("img/banner-example.png") + "\">";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.