2

I have an ASP.NET MVC3 site where I need to show some account-related stats in the sidebar

I have a RenderAction in the layout i.e.

@{ Html.RenderAction("GetStats", "MyController"); }

and the action method in MyController returns some text

  [HttpGet]
   public ContentResult GetStats()
   {
    ... snip (get stats from cache/db as the case may be)....
    return Content(String.Format("Your stats: {0}", stats));
   }

which works fine under normal circumstances.

However, say the view contains a form, and if a server-side model validation error is thrown, then the the render action returns a 404 view embedded where the stats should be. The rest of the page shows up fine, with the correct validation message etc.

I also tried using a regular partial view instead of a ContentResult with the same results.

seekay
  • 2,493
  • 3
  • 27
  • 33
  • 1
    Found the problem - adding it as a comment so that I can kick myself if I do this again. The issue was that I had a [HttpGet] on the controller action, which means that naturally it won't work when a form is submitted i.e. a POST. – seekay Dec 06 '11 at 22:05
  • You should post it as an answer. – Felipe Miosso Apr 24 '16 at 14:00

0 Answers0