Why am I required to use the <text>
tag to enclose the pipe literal '|' in this markup? Surely it is well outside the scope of the ActionLink method.
为什么我需要使用
@foreach (var item in Model.DetailItem.PlannedResources)
{
<tr>
<td>
@if (Model.ViewMode == ViewMode.Edit)
{
@Html.ActionLink("Edit", "Edit", new { id = item.PlannedResourceId }) <text>|</text>
@Html.ActionLink("Delete", "Delete", new {id = item.PlannedResourceId})
}
@Html.ActionLink("Details", "Details", new { id = item.PlannedResourceId })
</td>
<td>
| @item.ResourceType.Name
</td>
</tr>
}
If I don't use it, I get the error CS1525: Invalid expression term '|'
, but the second '|' gets by unhindered.
如果我不使用它,我得到错误CS1525:无效的表达式术语'|',但第二个'|'无阻碍地得到。
2 个解决方案
#1
20
It's because when you are inside a statement with {
and }
only HTML tags are considered as literals, everything else is server side script. So you need to either use standard HTML tags such as <div>
, <span>
, ... or if you want to use a literal use the special <text>
tag which is not outputted to the response.
这是因为当你在{和}语句中时,只有HTML标签被认为是文字,其他一切都是服务器端脚本。因此,您需要使用标准HTML标记,例如
#2
18
If your text spans multiple lines you can use the <text>
tag.<text>your text here...
over to the 2nd line.</text>
如果文本跨越多行,则可以使用
Alternately, if you simply want to output the pipe character use the @:
directive to specify text,
so @:|
will output |
, and the error message will disappear.
或者,如果您只想输出管道字符,请使用@:指令指定文本,因此@:|将输出|,并且错误消息将消失。
#1
20
It's because when you are inside a statement with {
and }
only HTML tags are considered as literals, everything else is server side script. So you need to either use standard HTML tags such as <div>
, <span>
, ... or if you want to use a literal use the special <text>
tag which is not outputted to the response.
这是因为当你在{和}语句中时,只有HTML标签被认为是文字,其他一切都是服务器端脚本。因此,您需要使用标准HTML标记,例如
#2
18
If your text spans multiple lines you can use the <text>
tag.<text>your text here...
over to the 2nd line.</text>
如果文本跨越多行,则可以使用
Alternately, if you simply want to output the pipe character use the @:
directive to specify text,
so @:|
will output |
, and the error message will disappear.
或者,如果您只想输出管道字符,请使用@:指令指定文本,因此@:|将输出|,并且错误消息将消失。