Any*_*One 1 .net asp.net-mvc razor
我试图在剃刀页面下面写下简单的代码,但它总是给出错误.
( @gallery.Images.Count images ) // expect : ( 23 images )
Run Code Online (Sandbox Code Playgroud)
但奇怪的是下面的代码工作
(@Model.RateCount rates)
Run Code Online (Sandbox Code Playgroud)
我收到编译错误而不是运行时异常
完整的cshtml页面如下所示.
@using Something.UI.Models.ViewModels
@model List<ImageGalleryUI>
<div class="albumlist">
@foreach (ImageGalleryUI gallery in Model)
{
<a href="@Html.ActionLinkRef(gallery.DisplayAction)">
<img src="@gallery.AlbumImageSrc" alt="@gallery.AlbumName" width="150px"/>
</a>
@Html.ActionLink(gallery.DisplayAction)
( @gallery.Images.Count images )
}
</div>
Run Code Online (Sandbox Code Playgroud)
这是错误
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1646: Keyword, identifier, or string expected after verbatim specifier: @
Source Error:
Line 9: </a>
Line 10: @Html.ActionLink(gallery.DisplayAction)
Line 11: ( @{gallery.Images.Count} images )
Line 12: }
Line 13: </div>
Run Code Online (Sandbox Code Playgroud)
如果你还没有在顶部做过这样的事情
@{
gallery = new ...
}
Run Code Online (Sandbox Code Playgroud)
然后画廊不存在.
你确定你不是故意的@Model.gallery.Images.Count吗?
编辑
尝试更换
( @gallery.Images.Count images )
Run Code Online (Sandbox Code Playgroud)
同
@: ( @gallery.Images.Count images )
Run Code Online (Sandbox Code Playgroud)
应该运作得很好.问题是Razor正在解释(作为代码的一部分,而不是作为输出的一部分.把@:让Razor知道这一行上的内容是应该进入响应流的输出.
| 归档时间: |
|
| 查看次数: |
2681 次 |
| 最近记录: |