Search code examples
c#viewasp.net-mvc-5characteractionlink

Display a | character between CRUD View Action links


In a C# MVC5 Internet Application View, how can I display the | character between my CRUD View Action links when the links are in an if statement?

Here is my code:

<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>

Here is the error:

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

Thanks in advance

EDIT

I have removed the @ character as well as placed the | on each new line, and I get a compiler message each way.

Here is my code:

<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> 

The error is a compilation error, with the following message:

Compiler Error Message: CS1513: } expected

Solution

  • This will work.

    <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)
    }
    

    Just remove the @ before |

    OR Just write it as :

    <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)
    }