如何在给定条件的情况下隐藏html.actionlink按钮

时间:2017-05-30 07:14:56

标签: c# visual-studio razor

<tbody>
    @foreach (var item in Model.Roles)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @foreach (var permission in item.Permissions)
                {
                    @Html.DisplayFor(modelItem => permission)
                    <br/>
                }

           </td>
           <td>
                        @Html.ActionLink("Edit", "EditRole", > "Roles", new { RoleID = item.RoleID}, null) // i want when RoleID = 1, it will > hide the button
                @{ if (item.RoleID == 1) // this is the condition
                    {
                        @:style = "display:none"
                    }
                }
            </td>
        </tr>
    }
</tbody>

2 个答案:

答案 0 :(得分:0)

您好,你可以使用这个

#include <stdio.h>

void swap(int *xp, int *yp) {
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

// A function to implement bubble sort
void bubbleSort(int arr[], int n) {
    int i, j;
    for (i = 0; i < n - 1; i++)

        // Last i elements are already in place
        for (j = 0; j < n - i - 1; j++)
            if (arr[j] > arr[j + 1])
                swap(&arr[j], &arr[j + 1]);
}

/* Function to print an array */
void printArray(int arr[], int size) {
    for (int i = 0; i < size; i++)
        printf("%d ", arr[i]);
    printf("\n");
}

int main() {
    int arr[] = {64, 34, 25, 12, 22, 11, 98};
    int arr_original[] = {64, 34, 25, 12, 22, 11, 98};
    int rank[7];

    int n = sizeof(arr) / sizeof(arr[0]);
    bubbleSort(arr, n);

    printf("Sorted array: \n");
    printArray(arr, n);

    //PLACE RANK
    //look for location of number in original array
    //place the location in rank array
    int counter = 1;
    for (int k = 0; k < n; k++){
        for (int i = 0; i < n; i++){
            printf("Checking..%d\n", i);
            if (arr_original[i] == arr[k]){
                rank[i] = counter;
                counter++;
                printf("Found..%d\n", i);
            }
        }
    }

    printf("Original array: \n");
    printArray(arr_original, n);

    printf("Rank array: \n");
    printArray(rank, n);
    return 0;
}

答案 1 :(得分:0)

您可以这样做,通过ActionLink参数声明HTML属性上的style属性:

@if (item.RoleID == 1)
{
    @Html.ActionLink("Edit", "EditRole", "Roles", new { RoleID = item.RoleID}, null) 
}
else
{
   @Html.ActionLink("Edit", "EditRole", "Roles", new { RoleID = item.RoleID }, new { @style = "display:none" })
}