PDA

View Full Version : [CLOSED] msg.Alert() not working



susanz
Sep 03, 2014, 3:38 AM
I have controller code:



public ActionResult SaveGridDataChanges(StoreDataHandler handler, int gridID)
{
ChangeRecords<Object> rows = handler.BatchObjectData<Object>();

try
{
...
}
}
catch (Exception e)
{
X.Msg.Alert("Error:", e.Message).Show();
// X.Msg.Notify("Error:", e.Message).Show();
}
return this.Direct()
}


not sure why is Notify() works but Alert() display no message ?
Thanks
-susan

geoffrey.mcgill
Sep 03, 2014, 6:59 AM
The code you have posted appears to be correct.

Please ensure you wrap all code samples in [CODE] tags.

The Forum Guidelines provide tips on posting in the forums:

http://forums.ext.net/showthread.php?10205-More-Information-Required (http://forums.ext.net/showthread.php?10205-More-Information-Required)

susanz
Sep 03, 2014, 4:22 PM
tag added to prev request. still not working. I switched to use global error handling as below. the onAjaxException() never been called. Could you help spot any API error? what is good way to debug this ?
Thanks
-susanz
[Code]

@(Html.X().ResourceManager()
//.ShowWarningOnAjaxFailure (false)
.Listeners(l =>
{
l.AjaxRequestException.Handler = "onAjaxException";
})
)

<script>
var onAjaxException = function (response, result, el, eventType, action, extraParams, o) {
alert("Ajex exception called=" + eventType)
if (eventType === 'event') {
//ajax event already has its own error handler
return;
}

Ext.Msg.alert('Error', result.errorMessage);

// return false will stop event from bubbling
return false;
}
</script>

//direct event
public ActionResult SaveGridDataChanges(StoreDataHandler handler, int gridID)
{
ChangeRecords<Object> rows = handler.BatchObjectData<Object>();

try
{
throw new Exception(" test error");

}
catch (Exception e)
{
//CPMAppUtil.LogError ("Error SaveCubeDataBulk gridid= " + gridID, e);
ResourceManager.AjaxSuccess = false;
ResourceManager.AjaxErrorMessage = "Data has no change";// not show
throw e;
}

return this.Direct();
}

Daniil
Sep 04, 2014, 9:48 AM
As for the original post.

Both, X.Msg.Alert and X.Msg.Notify don't appear for me. It happens because a sync request doesn't executed a response JavaScript code automatically.

As for global handling. Yes, it is possible, but it might be a bit problematic to extract an error message.

I would recommend this approach.

View

@{
var X = Html.X();
}

<!DOCTYPE html>
<html>
<head>
<title>Ext.Net.MVC v2 Example</title>

<script>
var onStoreException = function (propxy, response, operation) {
var message = operation.getError();

Ext.net.Notification.show({
iconCls: 'icon-exclamation',
html: message,
title: 'EXCEPTION',
hideDelay: 5000,
});
};
</script>
</head>
<body>
@X.ResourceManager()

@(X.Store()
.ID("Store1")
.Model(X.Model().Fields("test"))
.Proxy(X.AjaxProxy()
.API(action =>
{
action.Read = "GetData";
action.Sync = "Sync";
})
.Reader(X.JsonReader().MessageProperty("message"))
)
.ShowWarningOnFailure(false)
.Listeners(events =>
{
events.Exception.Fn = "onStoreException";
})
)

@X.Button().Text("Sync").Handler("App.Store1.getAt(0).set('test','new value'); App.Store1.sync({});")
</body>
</html>


Controller

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

public ActionResult GetData()
{
return this.Store(new object[]
{
new
{
test = "Hello"
}
});
}

public ActionResult Sync(StoreDataHandler handler)
{
try
{
throw new Exception("Some Error");
}
catch(Exception e)
{
return this.Store(e.Message);
}

return this.Store(new object[] {});
}

susanz
Sep 04, 2014, 7:11 PM
Great! That works.
Thanks
-susanz