[CLOSED] Getting error from Content/ItemsFromAction

  1. #1

    [CLOSED] Getting error from Content/ItemsFromAction

    I want to build out a menu panel from the controller. I seem to be missing something - maybe a property that needs a value?

    View
    @{
        ViewBag.Title = "Test";
    }
    
    <h2>Test</h2>
    
    @(
        Html.X().Panel()
            .ID("WestMenuPanel")
            .Width(250)
            .Title("Menu Bar")
            .Collapsible(true)
            .Split(true)
            .MaxWidth(380)
            .ItemsFromAction("GetMenu", new { containerId = "WestMenuPanel" })
    )
    Controller
    //
    // GET: /Test/
    public ActionResult Test()
    {
        return View();
    }
    
    public ContentResult GetMenu(string containerId)
    {
        ContentResult cr = new ContentResult();
    
        MenuPanel mp = new MenuPanel() { ID = "MenuPanel1", Title = "Menu Panel", Collapsible = true };
    
        Ext.Net.MenuItem m1 = new Ext.Net.MenuItem("Item1");
        Ext.Net.MenuItem m2 = new Ext.Net.MenuItem("Item2");
    
        mp.Menu.Items.Add(m1);
        mp.Menu.Items.Add(m2);
    
        string script = @"<script>{0}</script>";
    
        cr.Content = String.Format(script, mp.ToScript(RenderMode.AddTo, containerId));
    
        return cr;
    }
    Error and Resulting HTML:
    SCRIPT5007: Unable to get value of the property 'add': object is null or undefined 
    
    <!DOCTYPE html>
    <html>
    <head>
        <link type="text/css" rel="stylesheet" href="/extjs/resources/ext_theme_gray/ext-theme-gray-all-embedded-css/ext.axd?v=41185" id="ext-theme" />
        <link type="text/css" rel="stylesheet" href="/extnet/resources/css/extnet-all-embedded-css/ext.axd?v=41185" />
        <script type="text/javascript" src="/extjs/ext-all-js/ext.axd?v=41185"></script>
        <script type="text/javascript" src="/extnet/extnet-all-js/ext.axd?v=41185"></script>
    
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width" />
        <title>Valise</title>
    
        <script type="text/javascript">
        //<![CDATA[
            Ext.net.ResourceMgr.init({isMVC:true,theme:"gray"});Ext.onReady(function(){Ext.create("Ext.panel.Panel",{id:"WestMenuPanel",maxWidth:380,renderTo:"App.WestMenuPanel_Container",width:250,split:true,items:[],collapsible:true,title:"Menu Bar"});});
        //]]>
        </script>
    </head>
        <body>
            
            
    
    <h2>Test</h2>
    
    <div id="App.WestMenuPanel_Container"></div><script>Ext.net.ResourceMgr.destroyCmp("App.MenuPanel1");Ext.getCmp("WestMenuPanel").add({id:"MenuPanel1",xtype:"netmenupanel",collapsible:true,title:"Menu Panel",menu:{floating:false,xtype:"menu",items:[{text:"Item1"},{text:"Item2"}]}});<
    Last edited by Daniil; May 10, 2013 at 1:59 PM. Reason: [CLOSED]
  2. #2
    ItemsFromAction expects PartialViewResult only
    You cannot use ContentResult
    Vladimir Shcheglov
    Sr. Developer
  3. #3
    Ok. I changed my view to this:
    @(
     Html.X().Panel()
            .ID("WestMenuPanel")
            .Width(250)
            .Title("Menu Bar")
            .Collapsible(true)
            .Split(true)
            .MaxWidth(380)
            .AutoDoLayout(true)
            .Loader(
                Html.X().ComponentLoader()
                    .AutoLoad(true)
                    .DisableCaching(true)
                    .Url(Url.Action("GetMenu"))
                    .ReloadOnEvent(true)
                    .Params(new { containerId = X.GetCmp<Panel>("WestMenuPanel").ID })
            )
    )
    I no longer get an error, but the menu panel is not loading into my panel.

    I also tried:
           .Loader(
                Html.X().ComponentLoader()
                    .ID("ComponentLoader1")
                    .AutoLoad(true)
                    .DisableCaching(true)
                    .Url(Url.Action("GetMenu"))
                    .ReloadOnEvent(true)
                    .Params(new { containerId = X.GetCmp<ComponentLoader>("ComponentLoader1").ID })
            )
    Still no error, and no menu panel.

    I looked at the source and the containerId is being passed. Is the controller code wrong?
  4. #4
    Hello!

    Try the following:

    Controller:

    public ActionResult Index()
    {
    	return View();
    }
    
    public ActionResult GetMenu(string containerId)
    {
    	MenuPanel mp = new MenuPanel() { ID = "MenuPanel1", Title = "Menu Panel", Collapsible = true };
    
    	Ext.Net.MenuItem m1 = new Ext.Net.MenuItem("Item1");
    	Ext.Net.MenuItem m2 = new Ext.Net.MenuItem("Item2");
    
    	mp.Menu.Items.Add(m1);
    	mp.Menu.Items.Add(m2);
    
    	return this.ComponentConfig(mp);
    }
    View:

    @(
     Html.X().Panel()
            .ID("WestMenuPanel")
            .Width(250)
            .Title("Menu Bar")
            .Collapsible(true)
            .Split(true)
            .MaxWidth(380)
            .AutoDoLayout(true)
            .Loader(
                Html.X().ComponentLoader()
                    .AutoLoad(true)
                    .Url(Url.Action("GetMenu"))
                    .Mode(LoadMode.Component)
            )
    )
  5. #5
    Works great! Thanks Baidaly!

Similar Threads

  1. dynamic load content error in IE
    By wentai2011 in forum 1.x Help
    Replies: 1
    Last Post: Jul 24, 2011, 1:55 PM
  2. Content Encoding Error v1.0
    By king1231986 in forum 1.x Help
    Replies: 2
    Last Post: Jan 22, 2011, 3:18 AM
  3. htttp content compression error
    By Oread in forum 1.x Help
    Replies: 7
    Last Post: Jan 19, 2011, 10:09 AM
  4. IIS 7.5 WebConfig and http content compression error
    By king1231986 in forum 1.x Help
    Replies: 1
    Last Post: Jan 19, 2011, 9:43 AM
  5. Replies: 2
    Last Post: Jan 20, 2009, 11:21 AM

Tags for this Thread

Posting Permissions