I am developing an ASP.NET MVC3 application with Razor and C#. I wanted to know if there is any way to "disable" an hyperlink rendered with the Html.ActionLink
helper without spoiling my View with if constructs. As for disable I mean the link becomes not clickable, greyed out and without the underline.
To make things clear I hereby attach the as-is code I currently use to make the trick. Instead of disabling the hyperlink I just display N/A as plain text.
The part of the View:
<td>@if(topic.EnableTopicDownloadLink)
{
@Html.ActionLink("Presentation", "Download", new { topicId = topic.TopicId })
}
else
{
@Html.Raw("N/A");
}
</td>
<td>@if (topic.EnableTopicWatchLink)
{
@Html.ActionLink("Video", "Play", new { topicId = topic.TopicId })
}
else
{
@Html.Raw("N/A");
}
</td>
And the ViewModel passed to the View
public class TopicDownloadViewModel
{
public int TopicId { get; set; }
public string TopicName { get; set; }
public string TopicPresenter { get; set; }
public string TopicStartTime { get; set; }
public string TopicEndTime { get; set; }
public bool EnableTopicWatchLink { get; set; }
public bool EnableTopicDownloadLink { get; set; }
public TopicDownloadViewModel(WebinarTopic webinarTopic)
{
TopicId = webinarTopic.TopicId;
TopicName = webinarTopic.TopicName;
TopicPresenter = webinarTopic.TopicPresenter;
TopicStartTime = String.Format("{0:t}", webinarTopic.TopicStartTime);
TopicEndTime = String.Format("{0:t}", webinarTopic.TopicEndTime);
EnableTopicWatchLink = (webinarTopic.TopicVideoWatchLink != null) ? true : false;
EnableTopicDownloadLink = (webinarTopic.TopicSlidesDownloadLink != null) ? true : false;
}
}
I know there is a disabled HTML attribute for <a>
but the only way to enable the link is to omit the attribute and I have no clue how to do it without using jQuery. My intension is not to use jquery if feasible.
Thanks
Francesco