显示| CRUD查看操作链接之间的字符

时间:2014-08-04 05:09:30

标签: c# view asp.net-mvc-5 character actionlink

在C#MVC5 Internet应用程序视图中,当链接在if语句中时,如何在CRUD View Action链接之间显示|字符?

这是我的代码:

<td>
    @if (item.mapLocationItemType.Equals("Video Gallery"))
    {
        @Html.ActionLink("Edit", "Edit", "MapLocationVideoGallery", new { id = item.Id }, null) @|
        @Html.ActionLink("Details", "Details", "MapLocationVideoGallery", new { id = item.Id }, null) @|
        @Html.ActionLink("Delete", "Delete", "MapLocationVideoGallery", new { id = item.Id }, null) @|
        @Html.ActionLink("Videos", "Index", "MapLocationVideo", new { mapLocationVideoGalleryId = item.Id }, null)
    }
</td>

这是错误:

Parser Error Message: "|" is not valid at the start of a code block.  Only identifiers, keywords, comments, "(" and "{" are valid.

提前致谢

修改

我删除了@字符以及放置了|在每一个新行上,我都会收到编译器消息。

这是我的代码:

<td>
    @if (item.mapLocationItemType.Equals("Video Gallery"))
    {
        @Html.ActionLink("Edit", "Edit", "MapLocationVideoGallery", new { id = item.Id }, null) 
        |
        @Html.ActionLink("Details", "Details", "MapLocationVideoGallery", new { id = item.Id }, null) 
        |
        @Html.ActionLink("Delete", "Delete", "MapLocationVideoGallery", new { id = item.Id }, null) 
        |
        @Html.ActionLink("Videos", "Index", "MapLocationVideo", new { mapLocationVideoGalleryId = item.Id }, null)
    }
</td>

<td>
    @if (item.mapLocationItemType.Equals("Video Gallery"))
    {
        @Html.ActionLink("Edit", "Edit", "MapLocationVideoGallery", new { id = item.Id }, null) |
        @Html.ActionLink("Details", "Details", "MapLocationVideoGallery", new { id = item.Id }, null) |
        @Html.ActionLink("Delete", "Delete", "MapLocationVideoGallery", new { id = item.Id }, null) |
        @Html.ActionLink("Videos", "Index", "MapLocationVideo", new { mapLocationVideoGalleryId = item.Id }, null)
    }
</td> 

错误是编译错误,并显示以下消息:

Compiler Error Message: CS1513: } expected

2 个答案:

答案 0 :(得分:0)

这样可行。

<td>
@if (item.mapLocationItemType.Equals("Video Gallery"))
{
    @Html.ActionLink("Edit", "Edit", "MapLocationVideoGallery", new { id = item.Id }, null) |
    @Html.ActionLink("Details", "Details", "MapLocationVideoGallery", new { id = item.Id }, null) |
    @Html.ActionLink("Delete", "Delete", "MapLocationVideoGallery", new { id = item.Id }, null) |
    @Html.ActionLink("Videos", "Index", "MapLocationVideo", new { mapLocationVideoGalleryId = item.Id }, null)
}

只需删除@ before |

或者只需将其写为:

<td>
@if (item.mapLocationItemType.Equals("Video Gallery"))
{
    @Html.ActionLink("Edit", "Edit", "MapLocationVideoGallery", new { id = item.Id }, null)  @:|
    @Html.ActionLink("Details", "Details", "MapLocationVideoGallery", new { id = item.Id }, null)  @:|
    @Html.ActionLink("Delete", "Delete", "MapLocationVideoGallery", new { id = item.Id }, null)  @:|
    @Html.ActionLink("Videos", "Index", "MapLocationVideo", new { mapLocationVideoGalleryId = item.Id }, null)
}

答案 1 :(得分:0)

@ | - 应该用简单的替换并且应该放在newLine(每个@ |)