Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The culprit code looks like this:</p> <pre><code>itemFactory.Add() .Text(menuItem.Caption) .Selected(menuItem.Selected) .Action(menuItem.Action, menuItem.Controller) .Enabled(menuItem.Enabled) .Visible(menuItem.Visible) ; </code></pre> <p>This C# code is building a Telerik PanelBar (menu). The various methods of this 'fluent interface' are setting properties on the item that's being added.</p> <p>Unfortunately, one method doesn't do as you might expect: Action(actionName, controllerName).</p> <p>Rather than setting the controller action to be executed when the PanelBar item is clicked, calling this method actually executes the action on the controller.</p> <p>It seems this is done asynchronously, however, as tracing the above code showed that it ran almost instantly and therefore it was ruled out.</p> <p>The fix is to use the Url method, not the Action method, and build the Url using the ASP.NET MVC Url method. This is rather counter-intuitive, as the Telerik ASP.NET MVC framework surely should work with MVC first and URLs second, but we should have:</p> <ol> <li>Consulted the documentation rather than assuming what methods did</li> <li>Noticed that the app suddenly became slower by a large, fixed amount, on each page load</li> </ol> <p>I had been clueless after running a profiler, because it seemed that controller methods were being called that I didn't expect - and the origin of the calls seemed to be from Telerik's code (not ours). It was only when I removed the pieces of the Navigation partial view one at a time that I eventually discovered what Action() was doing.</p> <p>Asynchronous code is great, except when you try to debug/profile and can't find where it's called from!</p> <p>Thanks for the suggestions in the comments.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload