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" />
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.
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.
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>
@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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With