Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 3: Stack Overflow on a Html.Action?

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
like image 410
Zachary Scott Avatar asked Feb 15 '26 06:02

Zachary Scott


1 Answers

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.

like image 186
Andrew Barber Avatar answered Feb 21 '26 15:02

Andrew Barber



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!