【问题标题】:Space in attribute value gets replaced by " (quotation mark)属性值中的空格被替换为“(引号)
【发布时间】:2015-05-13 07:07:52
【问题描述】:

当我插入带有空格作为属性值的字符串时,它会被引号替换。 例如,

@foreach (string file in files) {
    <div class="item active">
       <img class="img-responsive" src=@file alt="Book cover">
    </div>
}

它被渲染为

<div class="item active">
    <img class="img-responsive"     src="c:\users\raghav" sharma\documents\visual="" studio="" 2013\projects\bookhive\bookhive\content\images\0007282311-1.jpg="" alt="Book cover">
</div>

这真的让我很生气。我不知道为什么会发生这种情况我已经搜索了整个互联网但到目前为止一无所获。

【问题讨论】:

  • 您能否详细说明。我想知道@file 默认包含什么(模型中文件的值)?

标签: html asp.net asp.net-mvc asp.net-mvc-3 razor


【解决方案1】:

在值周围使用引号,例如

src="@file"

这应该像这样包装@file 的值:

src="c:\users\raghav sharma\documents\visual="

Razor 解析器将足够智能,可以识别引号中的 @file 并将其替换为 @file 的值。

【讨论】:

    猜你喜欢
    • 2019-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    相关资源
    最近更新 更多