How do I insert an image using HTML.ActionLink?

r.r picture r.r · Sep 8, 2010 · Viewed 34.4k times · Source

how to insert image in html.actionlink - asp.net mvc?

i did it so, but it doesnt works.

<a href="<%= Html.ActionLink("search", "Search", new { searchText = "txtSearch" }, null); %>">
        <img alt="searchPage" style="vertical-align: middle;" height="17px"
            src="../../Stylesheets/search.PNG" title="search" />

Answer

Trimack picture Trimack · Sep 8, 2010

You are completely misusing the ActionLink helper. The helper actually produces the whole <a href=".." ></a> tag.

What you really want to use in this case (apart from your own written helper) is this:

<a href="<%= Url.Action("Search", new { searchText = "txtSearch" }) %>">
    <img alt="searchPage" style="vertical-align: middle;" height="17px"
        src="../../Stylesheets/search.PNG" title="search" />
</a>