Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 906
r.r Avatar asked Sep 08 '10 13:09

r.r


People also ask

How does HTML ActionLink work?

Html. ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.

How do you pass an ActionLink model?

The Lookup method's arguments match the named properties in the ActionLink. MVC4 allows you to pass the model automatically through URL variables, which is seen my second example. The docs for ActionLink show that none of that method's overloads accepts a viewmodel object.


2 Answers

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>
like image 66
Trimack Avatar answered Sep 19 '22 13:09

Trimack


@Trimack is 100% correct w/ MVC2. If people are searching for the MVC3 equivalent, here it is...

<a href="@Url.Action("Search", new { searchText = "txtSearch" })">
    <img alt="searchPage" style="vertical-align: middle;" height="17px" src="../../Stylesheets/search.PNG" title="search" /> 
</a> 
like image 36
WEFX Avatar answered Sep 21 '22 13:09

WEFX