[CLOSED] Problem with a Command.Url that not show the redirected page

  1. #1

    [CLOSED] Problem with a Command.Url that not show the redirected page

    Hi guys,
    I have a grid direct command with a url redirect and some parameter.
    This is the portion of code into the caller cshtml file:
        
    .Commands(
                           Html.X().GridCommand()
                               .CommandName("Edit")
                               .Icon(Icon.NoteEdit)
                                   .ToolTip(t =>
                                   {
                                       t.Text = "Modifica della ripartizione ferie per giorno";
                                   })
                               )
                               .ID("EDITID1")
                           .DirectEvents(
                                   directEvents =>
                                   {
                                       directEvents.Command.Url = "/PianoFerieOreMese";
                                       directEvents.Command.Action = "";
                                       directEvents.Command.ExtraParams.Add(
                                           new Ext.Net.Parameter()
                                               {
                                                   Name = "Matricola",
                                                   Value = "record.data.Matricola",
                                                   Mode = ParameterMode.Raw,
                                               }
                                           );
                                       directEvents.Command.ExtraParams.Add(
                                           new Ext.Net.Parameter()
                                           {
                                               Name = "CodAz",
                                               Value = "record.data.CodAz",
                                               Mode = ParameterMode.Raw,
                                           }
                                           );
                                          
                                   })
    Both the controller file and cshtml file of the redirected are processed correcly, but the csthml file will not be rendered into the browser.
    Why? How do i have to do in order to perform display?
    Thanks
    Marco

    I have two zip with sample code but i'm unable to attach it.
    Last edited by Daniil; Oct 24, 2014 at 5:36 AM. Reason: [CLOSED]
  2. #2
    Hi Marco,

    Zip is not allowed to attach.

    Please post the code directly here as plain text. Please wrap the code in [CODE] tags.

    Ideally, we should be able to copy, paste and run the code without any changes from our side.
    Last edited by Daniil; Oct 16, 2014 at 1:14 PM.
  3. #3
    Calendar View ( You almost have to remove layout related things )
    @using Ext.Net;
    @using Ext.Net.MVC;
    
    @model List<It.EBillings.CIRFOOD.POC.Models.MonthModel>
    
    @{
        ViewBag.Title = "Test";
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    
    @section container {
        <style type="text/css">
            .SatStyle {
                background-color: beige !Important;
            }
    
            .SunStyle {
                background-color: bisque !Important;
            }
        </style>
    
        @{
            var items = new List<AbstractComponent>();
            foreach (var model in Model)
            {
                items.Add(It.EBillings.CIRFOOD.POC.Controllers.CalendarController.CreateGrid(model));    //// Need this method
            }
        }
    
        @(Html.X().Panel()
            .ID("MonthsPanel")
            .Layout(LayoutType.Auto)
            .AutoScroll(true)
            .Items(items))
    }
    Calendar Controller ( You almost have to remove layout related things )
    using Ext.Net;
    using It.EBillings.CIRFOOD.POC.Models;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Linq;
    using System.Security.Policy;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.UI.WebControls;
    
    namespace It.EBillings.CIRFOOD.POC.Controllers
    {
        public class CalendarController : Controller
        {
            public ActionResult Index()
            {
                var TheModel = new List<MonthModel>();
                int[] array = new int[31];
                for (int i = 0; i < 31; i++)
                {
                    array[i] = 5;
                }
    
                TheModel.Add(new MonthModel() { Year = 2014, MonthNo = 1, DayValues = array });
                TheModel.Add(new MonthModel() { Year = 2014, MonthNo = 2, DayValues = array });
                TheModel.Add(new MonthModel() { Year = 2014, MonthNo = 3, DayValues = array });
                TheModel.Add(new MonthModel() { Year = 2014, MonthNo = 4, DayValues = array });
                TheModel.Add(new MonthModel() { Year = 2014, MonthNo = 5, DayValues = array });
                TheModel.Add(new MonthModel() { Year = 2014, MonthNo = 6, DayValues = array });
                TheModel.Add(new MonthModel() { Year = 2014, MonthNo = 7, DayValues = array });
                TheModel.Add(new MonthModel() { Year = 2014, MonthNo = 8, DayValues = array });
                TheModel.Add(new MonthModel() { Year = 2014, MonthNo = 9, DayValues = array });
                TheModel.Add(new MonthModel() { Year=2014, MonthNo = 10, DayValues = array });
                TheModel.Add(new MonthModel() { Year = 2014, MonthNo = 11, DayValues = array });
                TheModel.Add(new MonthModel() { Year = 2014, MonthNo = 12, DayValues = array });
                return View(TheModel);
            }
    
            public static GridPanel.Builder CreateGrid(MonthModel mese)
            {
                var X = Html.X();
                int year = mese.Year;
                int month = mese.MonthNo;
    
                Store store1 = new Store();
                store1.ID = string.Format("store{0}{1}", year, month);
                GridPanel grid = new GridPanel();
                grid.ID = string.Format("{0}{1}", year, month);
                grid.Title =string.Format("{0} {1}", GetMonthName(year, month), year);
                Ext.Net.Model model = new Model();
                ////
                grid.Buttons.Add(
                    X.Button()
                        .Text("Sync")
                        .Icon(Icon.Disk)
                        .ID(string.Format("btnSync{0}{1}", month, year))
                        .DirectEvents(de => {
                            de.Click.Url = "Url.Action('HandleChanges')";
                            de.Click.ExtraParams.Add(new Ext.Net.Parameter
                            {
                                Name = "data",
                                Value = "this.up('grid').store.getChangedData({skipIdForPhantomRecords : false})",
                                Mode = ParameterMode.Raw,
                                Encode = true
                            });
                        }));
    
                ////
                foreach (DateTime s in giorniDelMese(year, month))
                {
                    string colName = GetDataIndexFormat(s);
                    ModelField modelField = new ModelField();
                    modelField.Name = colName;
                    modelField.Type = ModelFieldType.Int;
                    model.Fields.Add(modelField);
    
                }
    
                store1.Model.Add(model);
                store1.DataSource = GetDataTable(mese);
                store1.DataBind();
                grid.Store.Add(store1);
                grid.SelectionModel.Add(new RowSelectionModel { Mode = SelectionMode.Single });
    
                CellEditing plugEdit = new CellEditing();
                plugEdit.ClicksToEdit = 1;
                grid.Plugins.Add(plugEdit);
    
                ColumnBase[] cols = new ColumnBase[31];
    
                int ix = 0;
                foreach (DateTime d in giorniDelMese(year, month))
                {
                    Column tC = new Column();
                    tC.Text = string.Format("{0} {1}", d.Day, FirstCharUpper(d.ToString("ddd")));
                    tC.DataIndex = GetDataIndexFormat(d);
                    tC.Width = Unit.Pixel(40);
                    tC.Align = Alignment.Right;
                    tC.Sortable = false;
                    tC.Hideable = false;
                    tC.MenuDisabled = true;
    
                    if (d.ToString("ddd").Equals("sab"))
                    {
                        tC.TdCls = "SatStyle";
                        //tC.Cls = "SatStyle";
                    }
                    else if (d.ToString("ddd").Equals("dom"))
                    {
                        tC.TdCls = "SunStyle";
                        //tC.Cls = "SunStyle";
                    }
    
                    NumberField numField = new NumberField();
                    numField.MinValue = 0;
                    numField.MaxValue = 8;
                    numField.AllowBlank = false;
                    tC.Editor.Add(numField);
                    cols[ix] = tC;
                    ix++;
                }
    
                //empty cells
                while(ix != 31)
                {
                    Column tC = new Column();
                    tC.Text = string.Empty;
                    tC.DataIndex = string.Empty;
                    tC.Width = Unit.Pixel(40);
                    tC.Align = Alignment.Right;
                    tC.Sortable = false;
                    tC.Hideable = false;
                    tC.MenuDisabled = true;
    
                    cols[ix] = tC;
                    ix++;
                }
    
                CommandColumn rejCol = new CommandColumn();
                rejCol.Width = 70;
                rejCol.Commands.Add(
                            X.GridCommand()
                                .Text("Reject")
                                .ToolTip(t =>
                                {
                                    t.Text = "Reject row changes";
                                })
                                .CommandName("reject")
                                .Icon(Icon.ArrowUndo)
                       );
                rejCol.PrepareToolbar.Handler = "toolbar.items.get(0).setVisible(record.dirty);";
                rejCol.Listeners.Command.Handler = "record.reject();";
    
                grid.ColumnModel.Columns.Add(cols);
                grid.ColumnModel.Columns.Add(rejCol);
                return grid.ToBuilder();
            }
    
            public ActionResult HandleChanges(StoreDataHandler handler)
            {
                ChangeRecords<CalendarModel> persons = handler.BatchObjectData<CalendarModel>();
               
            }
    
            private static DataTable GetDataTable(MonthModel model)
            {
                DataTable table = new DataTable();
    
                for (int i = 0; i < 31; i++)
                {
                    string colName = string.Format("G{0}{1}", model.MonthNo, i);
                    table.Columns.Add(new DataColumn() { ColumnName = colName, DataType = typeof(int) });
                }
    
                   
                foreach (object[] obj in Data(model.DayValues))
                {
                    table.Rows.Add(obj);
                }
                return table;
            }
    
            private static string FirstCharUpper(string p)
            {
                return char.ToUpper(p[0]) + p.Substring(1);
            }
    
            private static object[] Data(int[] days)
            {
                //int totalDays = DateTime.DaysInMonth(year, month);
                int totalDays = days.Length;
                object[] temp = new object[totalDays];
    
                for (int i = 0; i < totalDays; i++)
                {
                    temp[i] = days[i];
                }
    
                object[] result = new object[1];
                result[0] = temp;
    
    
                return result;
            }
    
            private static string GetMonthName(int year, int month)
            {
                string result = new DateTime(year, month, 1).ToString("MMMM");
                result = FirstCharUpper(result);
                return result;
            }
    
            private static string GetDataIndexFormat(DateTime d)
            {
                return string.Format("G{0}{1}", d.Month, d.Day);
            }
    
            private static List<DateTime> giorniDelMese(int year, int month)
            {
                List<DateTime> giorni = new List<DateTime>();
                DateTime dDay;
                for (int day = 1; day <= DateTime.DaysInMonth(year, month); day++)
                {
                    dDay = new DateTime(year, month, day);
                    giorni.Add(dDay);
                }
                return giorni;
            }
    
        }
    }
    Calendar Model ( You almost have to remove layout related things )
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace It.EBillings.CIRFOOD.POC.Models
    {
        public class MonthModel
        {
            public int Year { get; set; }
            public int MonthNo { get; set; }
            public int[] DayValues { get; set; }
            public int[] PFRefs { get; set; }
        }
    }
    the launcher as described is a GridCommand in a grid like this :

    Html.X().GridCommand()
                                .CommandName("Edit")
                                .Icon(Icon.NoteEdit)
                                    .ToolTip(t =>
                                    {
                                        t.Text = "Modifica della ripartizione ferie per giorno";
                                    })
                                )
                                .ID("EDITID1")
                            .DirectEvents(
                                    directEvents =>
                                    {
                                        directEvents.Command.Url = "/Calendar";
                                        directEvents.Command.Action = "";
                                           
                                    })
    That is the sample code.
    Now I hope to have immediatly help to solve my issue, thanks,
    Marco
  4. #4
    ( You almost have to remove layout related things )
    Please provide us with the code that we can copy, paste and run without any changes.

    This code:
    de.Click.Url = "Url.Action('HandleChanges')"
    Please clarify have you noticed that the result URL is exactly "Url.Action('HandleChanges')".

    It means that "Url.Action(...)" is not considered as a method call, it is just a string.

    You can use:
    de.Click.Action = "HandleChanges";
  5. #5
    Thanks danil.
    I use
    directEvents.Command.Url = "/PianoFerieOreMese";
    because from the source view called Anagrafica when i press the GridButton I have to switch to PianoFerieOreMeseView ( see posted code )
    All seems to work fine, because if I put a break point at the end of the PianoFerieOreMese View it passes success, but the view will not be displayed.
    In sequence after the code line above in Anagrafica View the Init method of PianoFerieOreMese Controller pass succes then the PianoFerieOreMese View-Controller populate grid items for the panel items. Panel items are added success to panel. PianoFerieOreMese View don't appear in the browser.
    Why? Do i have omitted some call directive?
    Marco
    Last edited by marco.morreale; Oct 16, 2014 at 4:40 PM.
  6. #6
    I have to switch to PianoFerieOreMeseView ( see posted code )
    I searched for "PianoFerieOreMeseView" in the posted code - no appearances.

    Also I don't see this code line in the posted full code.
    directEvents.Command.Url = "/PianoFerieOreMese";
    I see it in the original code only, but it is just a piece of code.

    Please clarify is there any chance that we can reproduce the problem using the test case that you posted?
  7. #7
    I'm in release time and I have no time to spent to create a test solution.
    I think the problem is that DirectEvent command url implements a AJAX call.
    How can I have to do in order to have a view rendered as result of this AJAX call?
    Thanks in advance,
    Simone
  8. #8
    Maybe I have found the problem.
    I have to use Listener instead of CommandDirect Events.
    Can someone help me to do some step ahead from
    .Listeners(ls => ls.Command.Handler = "Ext.Msg.alert(command, record.data.company);")
    Instead of :
    Ext.Msg.alert(command, record.data.company);
    I have to create a custom JavaScript method that accept two parameters from record.data.
    Can someone hepl me?
    Thanks in advance,
    Simone
  9. #9
    I have to create a custom JavaScript method that accept two parameters from record.data.
    You can just replace the call to Ext.Msg.alert() with your own function name:

    .Listeners(ls => ls.Command.Handler = "doSomething(record.data.company);")
    You can define the JavaScript function on your Page.
    var doSomething = function (name) {
        alert(name);
    };
    Hope this helps.
    Geoffrey McGill
    Founder
  10. #10
    I'm in release time and I have no time to spent to create a test solution.
    I understand you. Though, you (and, probably, your colleagues) had time to ask the same question (seems the same) on the Premium Help forum, on the regular Help forum and on Stackoverflow. I see it is very urgent. Though, it often happens that a plain description is not enough to understand the problem well and help. The best chance to get an immediate help (as you are asking for) is to provide us with a test case to reproduce the problem. By the way, you also had time to post a test case which, seems, doesn't reproduce the problem (does it?). I don't quite get it. For me, it looks better to focus all the time and energy that you spent on the issue to create a test case for us.

    Though, hopefully the Geoffrey's answer helps.

Similar Threads

  1. Show/Hide Image Command from Code behind
    By Nagaraj K Hebbar in forum 1.x Help
    Replies: 2
    Last Post: Nov 26, 2013, 7:22 PM
  2. Replies: 1
    Last Post: Aug 14, 2013, 11:54 AM
  3. [CLOSED] How to show ext:Window on Parent page in Nested page
    By ViDom in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: May 09, 2012, 2:33 PM
  4. Replies: 0
    Last Post: Feb 23, 2012, 6:18 AM
  5. Show ExtNet.Msg.Alert on Command Event ?
    By Mohammad in forum 1.x Help
    Replies: 2
    Last Post: Oct 25, 2011, 5:55 AM

Tags for this Thread

Posting Permissions