隐藏或禁用MVC3 ActionLinks根据单元格值 [英] Hide or Disable MVC3 ActionLinks depending on cell value

查看:91
本文介绍了隐藏或禁用MVC3 ActionLinks根据单元格值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MVC3创造了我下面的表

MVC3 has created the following table for me

@foreach (var item in Model) {
<tr>
    <td>
        @Html.DisplayFor(modelItem => item.Author)
    </td>
    <td>
        @Html.DisplayFor(modelItem => item.Comment)
    </td>
     <td>
        @Html.ActionLink("Edit", "Edit", new { id=item.UserCommentID }) |
        @Html.ActionLink("Details", "Details", new { id=item.UserCommentID }) |
        @Html.ActionLink("Delete", "Delete", new { id=item.UserCommentID })
    </td>
</tr>

}

我相信大家之前已经无数次看到这样的事情。

I am sure everyone has seen this sort of thing a million times before.

有谁知道是否有隐藏或禁用取决于item.Author的Actionlinks的任何方式。

Does anyone know if there is any way of hiding or disabling the Actionlinks depending on the item.Author.

(我只想要一个作家能够编辑或删除自己的评论)

(I only want an author be able to Edit or Delete his own comments)

我想,答案可能在于使用jQuery,但我会很乐意与任何解决方案都没有。

I am thinking that the answer might lie with jQuery but I will be very happy with any solution at all.

非常感谢。

推荐答案

像这样

@if(item.Author == loggedInUserIdOrSomethingYouWantToCompareTo) {
    <text>
    @Html.ActionLink("Edit", "Edit", new { id=item.UserCommentID }) |
    @Html.ActionLink("Details", "Details", new { id=item.UserCommentID }) |
    @Html.ActionLink("Delete", "Delete", new { id=item.UserCommentID })
    </text>
}

显然,你还是应该检查控制器端,以确保用户有权限(这将是容易假货这些URL)。

obviously you should still check on the controller side to make sure the user has the permissions (it would be easy to "fake" these URLs).

这篇关于隐藏或禁用MVC3 ActionLinks根据单元格值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆