PDA

View Full Version : [CLOSED] Grid Error Handling



adelaney
Jun 11, 2012, 1:02 PM
When using your Grid with MVC, do you have any good examples of / best practices for error handling?

Daniil
Jun 11, 2012, 2:48 PM
Hi,

Unfortunately, we have no such example at the moment.

Though it should not be difficult.

To handle errors you need:

1. Set up

MessageProperty="message"
for the Store Reader.

2. Use the StoreResult Success and Message properties.

3. Handle the Exception event of Store or its Proxy.

For example, getting an error message (which you set up for a StoreResult) within the Proxy Exception listener would look like this:

<ext:AjaxProxy>
<Listeners>
<Exception Handler="alert(operation.getError());" />
</Listeners>
</ext:AjaxProxy>

See also
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.proxy.Server-event-exception

adelaney
Jun 11, 2012, 5:29 PM
Ok. I thought that was simple enough, but apparently not. When I have this combination:


Proxy:

.Proxy(Sub(proxy)
Dim prxy As New Ext.Net.AjaxProxy()
With prxy
.API.Create = Url.Content("~/Assignments/_AddTeam/")
.API.Read = Url.Content("~/Assignments/_GetTeams/") + MvcApplication.CurrentApplicationUser.EmployeeID.T oString()
.API.Update = Url.Content("~/Assignments/_EditTeam")
.API.Destroy = ""
.Json = True
.Reader.Add(New Ext.Net.JsonReader() With {.Root = "Data", .AutoDataBind = True})
End With

proxy.Add(prxy)
End Sub) _


With this code:

<HttpPost()>
Public Function _AddTeam(ByVal team As Models.CWTeam()) As Ext.Net.MVC.StoreResult
Dim grid As New Ext.Net.MVC.StoreResult()

If team IsNot Nothing Then
Dim results As New List(Of Models.CWTeam)
Dim svc As New Services.TeamService

For Each tm In team
Try
results.Add(svc.CreateTeam(tm))
grid.Data = results
Catch ex As SystemException
grid.Message = ex.Message
End Try
Next

Return grid
Else
Return grid
End If
End Function

It throws a build error. When setting up the grid for error handling, am I supposed to use some other construct than the Proxy in the Razor syntax?
My code builds fine when returning a regular ActionResult from the Function that returns a view.

Daniil
Jun 11, 2012, 8:37 PM
It throws a build error.

Please always provide a bit more details about errors. So, please clarify what exactly error?



When setting up the grid for error handling, am I supposed to use some other construct than the Proxy in the Razor syntax?


Well, everything should look the same in Razor in that aspect.