2

By definition I had to post this question. I received the error on this line using ASP.NET MVC 3 and ASPX form. Where's my typo?

<a href="<%= Html.Action("About", "Home") %>">
<img src="<%= Url.Content("~/Content/images/newfront_04.jpg") %>" /></a>

StackOverflowException

I created a blank project to compare:

  • Web Config is identical minus connection strings (including Views web.config)
  • Global.asax.cs including routes is identical minus namespace
  • Page directive is identical
  • Home Controller code is identical minus namespace
  • Taking this line out makes everything work
  • The entire page is html with the exception of the page directive and ContentPlaceHolders
  • This is the Site.Master file
3
  • 1
    Can you post the code for your route? Also the declaration for the Action and any Attributes over the controller. Just basically anything that is going into the logic for picking the route. Commented Dec 15, 2011 at 5:09
  • Is a partial view involved by any chance? You may want to include some more of view. Commented Dec 15, 2011 at 5:12
  • I see what you did there Commented Dec 15, 2011 at 5:24

2 Answers 2

7

Html.Action is actually rendering that action where you are putting that code, and it's causing reentrancy there. That is: it's calling the whole action and outputting the resulting view... not outputting the url.

What you probably wanted was Html.ActionLink (which renders the whole A tag for you), instead, or Url.Action, to just output the URL - rather than the action result again.

Sign up to request clarification or add additional context in comments.

1 Comment

and again. and again. and again. +1
2

Try Url.Action instead of Html.Action

<a href="<%= Url.Action("About", "Home") %>">
<img src="<%= Url.Content("~/Content/images/newfront_04.jpg") %>" /></a>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.