0

I have these ActionLinks in my Main Index View:

<p>@Ajax.ActionLink("Releases", "Index", "Release", new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "ContentPanel" })</p>
<p>@Ajax.ActionLink("Templates", "Index", "Template", new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "ContentPanel" })</p>
<p>@Ajax.ActionLink("Testplans", "Index", "Testplan", new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "ContentPanel" })</p>

below is this:

<div id="ContentPanel">
    @RenderBody()
</div>

When I click each link Release,Templates, Testplans one after the other the switching of the views work.

When I click in this order:

Releases
Templates
Releases
Templates

The switching does not work anymore. The problem seems to be that when I set a breakpoint in my controller index method:

public ActionResult Index()
{
    return View();
}

The Index Action is called in a looooooop ??

Why this?

AliRıza Adıyahşi
  • 15,658
  • 24
  • 115
  • 197
Pascal
  • 12,265
  • 25
  • 103
  • 195
  • The problem seems to be the @RenderBody(). I do not need it, but I must use it as a asp.net mvc constraint. And in the Ajax.ActionLink I have to set an AjaxOptions... so one of them I must remove but then the functionality is broken. – Pascal Apr 18 '12 at 18:15
  • Do You use layout refrence in your view? like this Layout="/Shared/_Layout.cshtml"; – AliRıza Adıyahşi Apr 18 '12 at 18:21
  • yes thats in my _ViewStart.cshtml file defined. – Pascal Apr 18 '12 at 18:23
  • 1
    Could you try this code Layout = Request.IsAjaxRequest() ? null : "~/Views/Shared/_Layout.cshtml"; – AliRıza Adıyahşi Apr 18 '12 at 18:27
  • YES that helped! seems like a stupid workaround ;-) A last problem is there: In my MainController Index action method I return a View which is useless or the view is never visible. That means the Index action method is just useless code because my visible view is determined by the ActionLinks which one ActionLink will later be invoke from javascript code (First ActionLInk will be activated...) But the asp.net mvc design works that way that there must be an initial controller action call... Any solution to this? – Pascal Apr 18 '12 at 19:54
  • @AliRiza put your comment in a solution/answer so I can mark it as solved :) the problem I still have will be for a new question :) – Pascal Apr 19 '12 at 16:49
  • @AliRiza if you are interested ;-) http://stackoverflow.com/questions/10235554/hmtl-not-correct-rendered-and-no-viewbag-title-is-set-using-ajax-actionlinks – Pascal Apr 19 '12 at 19:43

1 Answers1

1

Could you try this code:

Layout = Request.IsAjaxRequest() ? null : "~/Views/Shared/_Layout.cshtml";
AliRıza Adıyahşi
  • 15,658
  • 24
  • 115
  • 197