[CLOSED] Show a modal dialog when exception is caught with message (MVC)

  1. #1

    [CLOSED] Show a modal dialog when exception is caught with message (MVC)

    We are trying to find a solution to show a modal message when an exception occurs . We tried this but is not working. If we assign it to the directEventUrl in the button it works but does not work if it is not event. How can we achieve this as this is a critial part of our devlopment.

    Index.cshtml
    @{
        ViewBag.Title = "Index";
    }
       @(Html.X().ResourceManager(ViewBag.ManagerConfig as MvcResourceManagerConfig))
    @(Html.X().Panel()
    .Items(items => items.Add(new TreePanel
                                  {
                                      ID = "exampleTree",
                                      Header = false,
                                      AutoScroll = true,
                                      Lines = false,
                                      UseArrows = true,
                                      CollapseFirst = false,
                                      RootVisible = false,
                                      Store = 
                                          {
                                              new TreeStore
                                                  {
                                                      Root = 
                                                          {
                                                              new Node
                                                                  {
                                                                      NodeID = "Root",
                                                                      Expanded = true
                                                                  }    
                                                          },
                        
                                                      Proxy = 
                                                          {
                                                              new AjaxProxy
                                                                  {
                                                                      API = 
                                                                          {
                                                                              Read = Url.Action("GetTreeNodes"),
                                    
                                   
                                                                          },
                                
                                
                                                                      ActionMethods = 
                                                                          {
                                                                              Read = HttpMethod.GET    
                                    
                                                                          },
                            
                                
                                
                                                                  }
                                                          } 
                                                  }    
                                          },
                                  }
                                 
                        ))
               )
    SampleController.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Ext.Net;
    using Ext.Net.MVC;
    namespace CompDesktop.Controllers
    {
        public class SampleController : Controller
        {
            //
            // GET: /Sample/
    
            public ActionResult Index()
            {
                return View();
            }
    
            public ActionResult GetTreeNodes()
            {
                var nc = new NodeCollection(false);
                try
                {
                    for (int i = 0; i < 10; i++)
                    {
                        Node n = new Node()
                        {
                            Text = "Node " + i,
                            IconCls = "",
                            Icon = Icon.Application
                        };
    
                        AddChildNode(n);
                        nc.Add(n);
                    }
                    //we are causing the exception for testing
                    int a = 0;
                    int b = 1;
                    int c = b / a;
                    return this.Content(c.ToString());
                }
                catch (Exception ex)
                {
                    //this is not working
                    X.MessageBox.Alert("Error", ex.Message).Show();
                    return this.Direct();
    
                }
            }
            private void AddChildNode(Node n)
            {
                for (int i = 0; i < 5; i++)
                {
                    n.Children.Add(new Node() { Text = "Child " + i, Icon = Icon.ApplicationDouble, Leaf = true });
                }
            }
    
        }
    }
    Last edited by Daniil; Dec 03, 2012 at 11:27 AM. Reason: [CLOSED]
  2. #2
    Hi Pawan,

    Please take a look at this example.

    Example View
    <!DOCTYPE html>
    
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>    
    </head>
    <body>
        @(Html.X().ResourceManager())
        @(
            Html.X().TreePanel()
                .Title("Tree")
                .Height(500)
                .Width(200)
                .Border(false)
                .Store(
                    Html.X().TreeStore()
                        .Proxy(
                            Html.X().AjaxProxy()
                                .Url(Url.Action("GetChildren"))
                                .Listeners(ls => ls.Exception.Handler = "alert(operation.getError());")
                                .Reader(Html.X().JsonReader().MessageProperty("message"))
                        )
                        .ShowWarningOnFailure(false)
                )
                .Root(
                    Html.X().Node().NodeID("0").Text("Root")
                )
        )
    </body>
    </html>
    Example Controller Action
    public StoreResult GetChildren(string node)
    {
        NodeCollection nodes = new Ext.Net.NodeCollection();
    
        if (!string.IsNullOrEmpty(node))
        {
            for (int i = 1; i < 6; i++)
            {
                Node asyncNode = new Node();
                asyncNode.Text = node + i;
                asyncNode.NodeID = node + i;
                nodes.Add(asyncNode);
            }
    
            for (int i = 6; i < 11; i++)
            {
                Node treeNode = new Node();
                treeNode.Text = node + i;
                treeNode.NodeID = node + i;
                treeNode.Leaf = true;
                nodes.Add(treeNode);
            }
        }
    
        //return this.Store(nodes.ToJson); // if success
        return this.Store("Some error occured"); //if error
    }

Similar Threads

  1. [CLOSED] message box rendering behind the modal window
    By SymSure in forum 2.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 10, 2012, 4:12 PM
  2. Replies: 1
    Last Post: Jan 27, 2012, 11:32 AM
  3. Replies: 7
    Last Post: Aug 12, 2011, 2:30 PM
  4. Show Modal window from a User Control
    By yourspraba in forum 1.x Help
    Replies: 1
    Last Post: Jun 29, 2010, 5:43 PM
  5. Ext.Msg.confirm as modal dialog
    By madhugumma in forum 1.x Help
    Replies: 0
    Last Post: Jul 24, 2009, 11:37 AM

Posting Permissions