.NET 6 MVC中嵌入Instagram图片遇@账户名报错的解决方法
.NET 6 MVC视图中Instagram嵌入代码@符号报错的解决办法
核心原因
在.NET Razor视图里,@是触发服务器端代码解析的特殊标记,嵌入代码里的@InstagramAccount会被Razor引擎误判为服务器端表达式,从而引发报错。
修改方案
直接对@符号进行转义——在Razor语法中,用两个连续的@@来表示一个普通的@符号,这样就能让页面正常渲染出Instagram账户名格式。
修改后的代码示例
<p style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; line-height:17px; margin-bottom:0; margin-top:8px; overflow:hidden; padding:8px 0 7px; text-align:center; text-overflow:ellipsis; white-space:nowrap;"><a href="https://www.instagram.com/p/CjLy3aqO-Cw/?utm_source=ig_embed&utm_campaign=loading" style=" color:#c9c8cd; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none;" target="_blank">A post shared by Mely's Underground-Cuisine (@@InstagramAccount)</a></p>
内容的提问来源于stack exchange,提问作者AlThePal78
相关产品推荐
相关产品推荐

