MVC3 How to disable/enable ActionLink

前端 未结 5 1567
鱼传尺愫
鱼传尺愫 2020-12-10 03:04

I have if condition and I want to disable or enable my actionLink button.

How would I do it?

@Html.ActionLink(\"Delete\", \"Delete\", new { id = @Mode

5条回答
  •  一向
    一向 (楼主)
    2020-12-10 03:35

    If you know on the server side that the link is not available then just render a message that the action is not available:

    @if(condition)
    {
       @Html.ActionLink("Delete", "Delete", new { id = @Model.Id})
    }
    else
    {
       Action is not available
    }
    

    Otherwise you can only disable a link with

    • CSS: Disable link using css
    • JS: How to enable or disable an anchor using jQuery?

    To make it work cross-browser: Should the HTML Anchor Tag Honor the Disabled Attribute?

提交回复
热议问题