Search code examples
asp.net-mvcimagehtml.actionlink

How do I insert an image using HTML.ActionLink?


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" />


Solution

  • 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>