user2232273
user2232273

Reputation: 4964

Image Hyperlink in ASP.NET - MVC 4

I try to create a project for the first time in asp.net (mvc4).

and what i try to do is to create a image which is a hyperlink to go to the index page.

i have search a lot of things and it shows very simple to do that.

but i can´t understand why it doesn´t work for me.

someone can give a hand?

Code:

<a href="<%= Url.Action("Index","Home")%><img src="~/Content/imagens/nav-arrow-back.png"/></a> 

The Action is "Index" in the controller calls Home.

Upvotes: 0

Views: 6449

Answers (2)

Snake Eyes
Snake Eyes

Reputation: 16764

you miss a quote

<a href="<%=Url.Action("Index","Home")%>">  ...
                                        ^
                                      about this quote you missed

For bad request, fix the whole <img> part

<img src="<%=Url.Content("~/Content/imagens/nav-arrow-back.png")%>"/>

Upvotes: 2

anaximander
anaximander

Reputation: 7140

First up, as previously noted you're missing a closing quote on that href. Second, MVC 4 doesn't use the <% %> syntax, at least not by default; it should be using Razor v2 which uses @, so your code should look like this:

<a href="@Url.Action("Index","Home")"><img src="~/Content/imagens/nav-arrow-back.png"/></a>

If you use the old syntax I assume it would try to handle the actual text <%= Url.Action("Index","Home")%> as a URL, which clearly won't work.

Upvotes: 1

Related Questions