PDA

View Full Version : [CLOSED] Getting error from Content/ItemsFromAction



jpadgett
May 09, 2013, 4:41 PM
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"}]}});<

Vladimir
May 09, 2013, 5:34 PM
ItemsFromAction expects PartialViewResult only
You cannot use ContentResult

jpadgett
May 09, 2013, 6:58 PM
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?

Baidaly
May 10, 2013, 12:31 AM
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)
)
)

jpadgett
May 10, 2013, 2:01 PM
Works great! Thanks Baidaly!