PDA

View Full Version : [CLOSED] FormCollection is empty in a MVC context after using beforeload store listener



Daly_AF
Oct 31, 2012, 1:29 PM
Hi,
I want to post search criteria values on FormCollection when loading GridPanel event this is the code below :

Controller Code:


public FormPanel CreateFP()
{
FormPanel fp = new FormPanel();
fp.ID = "_fp";
TextField txtField = new TextField();
txtField.ID = "_txt";
txtField.FieldLabel = "Txt";
Button btn = new Button();
btn.Text = "click";
btn.ID = "_btn";
btn.Listeners.Click.Handler = "onClick();";
fp.Items.Add(txtField);
fp.Items.Add(btn);
return fp;
}

public ContentResult LoadFP(String containerID)
{
ContentResult cr = new ContentResult();
String script = CreateFP().ToScript(RenderMode.AddTo, containerID);
//script += GenerateSearchScreensButtonKeyMap().ToScript();
cr.Content = string.Format("<script>{0}</script>", script);
return cr;
}

public ActionResult Research()
{
return View();
}

public StoreResult GetData(FormCollection value)
{
String txt = value["_txt"];
StoreResult sr = new StoreResult();
return sr;
}

public ActionResult StorePartial()
{
return Content(Ext.Net.ComponentLoader.ToConfig("~/Views/Research/StorePartial.ascx"));
}

[ASCX] Partial that contains GridPanel :


<ext:GridPanel runat="server">
<Store>
<ext:Store ID="Store1" runat="server">
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="Id" Type="Int" />
</Fields>
</ext:Model>
</Model>
<Proxy>
<ext:AjaxProxy Url="/Research/GetData">
<Reader>
<ext:JsonReader TotalProperty="total" Root="data">
</ext:JsonReader>
</Reader>
</ext:AjaxProxy>
</Proxy>
<Listeners>
<BeforeLoad Handler="onBeforeLoad(store, operation, App._fp);" />
</Listeners>
</ext:Store>
</Store>
<ColumnModel>
<Columns>
<ext:Column ID="Column1" runat="server" Text="ID" Width="40" DataIndex="Id" />
</Columns>
</ColumnModel>
</ext:GridPanel>

Main Page [Aspx]


<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html>
<html>
<head runat="server">
<script type="text/javascript">
var onClick = function () {
App._pnlLoader.removeAll();
App._pnlLoader.load(
{
url: "/Research/StorePartial",
params:
{
'containerID': '_pnlLoader'
}
});
};
var onBeforeLoad = function (store, operation, formPanel) {
var values = formPanel.getForm().getFieldValues();
var params = operation;
for (var v in values) {
params[v] = values[v];
}
};
</script>
</head>
<ext:ResourceManager runat="server">
</ext:ResourceManager>
<body>
<ext:Viewport ID="Viewport1" runat="server" Layout="BorderLayout" AutoScroll="true">
<Items>
<ext:Panel ID="_pnlCptySearchView" runat="server" Border="false" Header="false" Region="North">
<Loader ID="Loader1" runat="server" Url="/Research/LoadFP" DisableCaching="true"
Mode="Html" Scripts="true">
<Params>
<ext:Parameter Name="containerID" Value="App._pnlCptySearchView" Mode="Value" />
</Params>
</Loader>
</ext:Panel>
<ext:Panel ID="_pnlLoader" runat="server" Border="false" Header="false" Region="Center"
Layout="FitLayout">
<Loader ID="Loader2" runat="server" AutoLoad="false" Mode="Component" RemoveAll="true" />
</ext:Panel>
</Items>
</ext:Viewport>
</body>
</html>

Daniil
Oct 31, 2012, 4:32 PM
Hi @,

Please apply these changes.

1. Set up this for the AjaxProxy. FormCollection deals with a POST only.

<ActionMethods Read="POST" />

2. You should put any extra parameters into "operation.params".

var onBeforeLoad = function (store, operation, formPanel) {
var values = formPanel.getForm().getFieldValues();

operation.params = operation.params || {};
Ext.apply(operation.params, values);
};

Daly_AF
Oct 31, 2012, 4:44 PM
Thank you it works