根据单元格值隐藏或禁用 MVC3 ActionLink
MVC3 为我创建了下表
@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>
}
我相信每个人都已经见过这种事情一百万次了。
有谁知道是否有任何方法可以根据项目隐藏或禁用操作链接。作者。
(我只希望作者能够编辑或删除他自己的评论)
我认为答案可能在于 jQuery,但我会对任何解决方案感到非常满意。
非常感谢。
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.
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)
I am thinking that the answer might lie with jQuery but I will be very happy with any solution at all.
Many thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
像这样的事情
显然你仍然应该检查控制器端以确保用户具有权限(很容易“伪造”这些 URL)。
Something like this
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).
除了 Marek 的评论之外 - 请在当前用户发布/获取您的编辑页面时检查他们,以确保他们拥有对此的权限。我可以轻松地伪造一个链接来访问我应该访问的内容,甚至更改在编辑某些内容时必须篡改模型的任何隐藏表单值。
In addition to Marek's comments - please check the current user when they post/get your edit page as well to make sure they have permissions to this. I could easily forge a link to access something I should have access to or even change any hidden form values you have to tamper with the model when editing something.