我正在尝试使用 Razor 设置图像源,如下所示:
<img src=@myStringWithSpace>
问题是,有时 myStringWithSpace 中有空格。例如:
@Code Dim myStringWithSpace= "Alpha Romeo.jpg" EndCode
当呈现 html 时,我得到
<img src="Alpha" Romeo.jpg>
我想知道我怎样才能得到
<img src="Alpha Romeo.jpg">
最佳答案
您应该使用 @
前缀。
空间不是问题。空间将转换为 %20
您无需担心。您只需要确保将字符串的值括在单引号或双引号中。
<img src="@myStringWithSpace" alt="some alt text" />
或
<img src='@myStringWithSpace' alt="some alt text" />
关于asp.net-mvc - 如何在 Razor 中传递带空格的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38592241/