PDA

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



gets_gui
Jul 04, 2012, 2: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



items.Add(Html.X().Button()
.ID("searchButton")
.Text("Search")
.DirectEvents(directEvents =>
{
directEvents.Click.Url = "/Shared/OnSearchButtonDirectClick";
})
.Listeners(listeners =>
{
listeners.Click.Handler = "Ext.net.Bus.publish('Search.SearchButton', 'Search');";
}));


Code in 2nd Panel



Html.X().Panel()
.ID("Panel2")
.Title("Messages")
.Width(300)
.Height(300)
.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};
}

Daniil
Jul 04, 2012, 3:40 PM
Hi,

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?

gets_gui
Jul 04, 2012, 4: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.

Daniil
Jul 04, 2012, 4: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.

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

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

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