Rendering image as hyperlink in ASP.NET MVC without writing any helper extension method
Currently, I have code like this :
<% if (consumer.IsDischarged)
{ %>
<%= Html.ActionLink("<img src=\"../../Imag开发者_运维问答es/ConsumerImages/computer_go.png\" alt=\"discharged\" style=\"border:\"0\"/>", "Details", new { id = consumer.ApsId })%>
<%}
%>
Basically I want to show the hyperlinked image whenever the status of the isDischarged property of the consumer object is true. Any help or suggestions are highly appreciated.
a simple way could be
<a href="/Details/<%=consumer.ApsId%>"
<img src="../../Images/ConsumerImages/computer_go.png" alt="discharged" style="border:0"/>
</a>
You can try something like this. Use Url.Action
to get the url and then you can put insert the hyperlinked image normally rather than trying to use Html.ActionLink
.
<a href="<%= Url.Action("Details", new { id = consumer.ApsId }) %>">
<img src="../../Images/ConsumerImages/computer_go.png" alt="discharged" style="border:"0" />
</a>
精彩评论