View Full Version : [CLOSED] [RAZOR] MessageBus not triggering on duplicate message

Jul 04, 2012, 1:03 PM
I have an application which consists of 2 panels. I'm using the messagebus to notify the 2nd panel of actions (button presses, etc) selected on the 1st panel

My controller method is called the first time a new value is selected, but subsequent selection of the same option doesn't trigger the controller method

Code in 1st panel

.DirectEvents(directEvents =>
directEvents.Click.Url = "/Shared/OnSearchButtonDirectClick";
.Listeners(listeners =>
listeners.Click.Handler = "Ext.net.Bus.publish('Search.SearchButton', 'Search');";

Code in 2nd Panel

.MessageBusListeners(messageBus =>
messageBus.Add(new MessageBusListener()
Name = "Search.*",
Handler = "this.body.createChild({html: name + ' from ' + data, tag:'p'});" +
"$.ajax({ " +
"url: \"/Control2/MessageBusEvent\" + \"?data=\" + data," +
"success: function(data) { window.alert(data); }," +
"error: function(x, t, e) { window.alert(e); }," +
" });"

Controller Code

public JsonResult MessageBusEvent(string data)
string msg = X.Msg.Alert("DirectEvent", "MessageBusEvent " + data).ToScript();

// Do Stuff

return new JsonResult() { Data = msg, JsonRequestBehavior = JsonRequestBehavior.AllowGet};

Jul 04, 2012, 2:40 PM

It looks a cache issue.

To ensure the MessageBus listener is triggered please add the alert calling here:

Handler = "alert('The MessageBus listener is triggered'); this.body.createChild(...)"

Can you see this alert box on second and further clicks the button?

Jul 04, 2012, 3:02 PM
I've added the alert box as part of the handler. It is called in all instances of the Message firing, however I'm still only getting one call to the controller method.

Jul 04, 2012, 3:13 PM
It means we deal with the browser cache. The second and further times the response comes from the browser cache.

The respective OutputCache attribute for the controller action or a cache buster for the URL should help.

Jul 04, 2012, 3:51 PM
Do you have an example of setting the OutputCache attribute for the controller action or clearing the cache?

Jul 04, 2012, 3:59 PM
just add 'cache:false' to '$.ajax' argument object

Jul 04, 2012, 4:03 PM
perfect, thanks thats working now. Please close this issue