PDA

View Full Version : [CLOSED] Linked Comboboxes



romeu
May 11, 2012, 2:48 PM
Hi, We have a problem with linked comboboxes. When loading data from the second combobox is not being sent to the controller the selected value of the first combobox, generating the following error:

The parameters dictionary contains a null entry for parameter 'codigoEmpresa' of non-nullable type 'System.Int32' for method 'Ext.Net.MVC.AjaxResult ObterListaFiliaisEmpresa(Int32, Boolean)' in 'AthenasX.web.Areas.Administrativo.Controllers.Emp resaController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters

Below is the code of comboboxes and controller:



<ext:ComboBox ID="cmbEmpresa" runat="server" ValueField="Codigo" DisplayField="Fantaisa"
Editable="false" FieldLabel="Empresa" TypeAhead="true" QueryMode="Local" ForceSelection="true"
TriggerAction="All" SelectOnFocus="true">
<Store>
<ext:Store ID="dsEmpresasMasterPage" runat="server" WarningOnDirty="false">
<Proxy>
<ext:AjaxProxy Url="/athenasx/Empresa/ObterListaEmpresasPermitidas/">
<ActionMethods Read="POST" />
<Reader>
<ext:JsonReader Root="result" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="Fantaisa" />
<ext:ModelField Name="Codigo" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
<Items>
<ext:ListItem Text="Todas as Empresas" Value="0" />
</Items>
<SelectedItems>
<ext:ListItem Value="0" />
</SelectedItems>
<DirectEvents>
<Select Url="/athenasx/Empresa/SelecionarEmpresa">
<ExtraParams>
<ext:Parameter Name="codigoempresa" Value="Ext.encode(#{cmbEmpresa}.getValue())"
Mode="Raw" />
</ExtraParams>
</Select>
</DirectEvents>
</ext:ComboBox>
<ext:Store ID="dsFiliaisMasterPage" runat="server">
<Proxy>
<ext:AjaxProxy Url="/athenasx/Empresa/ObterListaFiliaisEmpresa/">
<ActionMethods Read="POST" />
<Reader>
<ext:JsonReader Root="result" />
</Reader>
</ext:AjaxProxy>
</Proxy>
<Model>
<ext:Model ID="Model1" runat="server">
<Fields>
<ext:ModelField Name="Fantasia" />
<ext:ModelField Name="Codigo" />
</Fields>
</ext:Model>
</Model>
<Parameters>
<ext:StoreParameter Name="codigoEmpresa" Value="Ext.encode(#{cmbEmpresa}.getValue())"
Mode="Raw" />
<ext:StoreParameter Name="incluirTodas" Value="true" Mode="Raw" />
</Parameters>
</ext:Store>
<ext:ComboBox ID="cmbFilial" runat="server" DisplayField="Fantasia" ValueField="Codigo"
Editable="false" FieldLabel="Filial" StoreID="dsFiliaisMasterPage" TypeAhead="true"
QueryMode="Local" ForceSelection="true" TriggerAction="All">
</ext:ComboBox>




public AjaxResult ObterListaEmpresasPermitidas()
{
var retorno = new List<Empresa>();

retorno = this.Repositorios.Empresa.ListaEmpresasUsuarioCorr ente(0).ToList();

var retorno2 = (from o in retorno
orderby o.Codigo
select new
{
o.Codigo,
o.Fantaisa
});

return new AjaxResult(retorno2);
}

public AjaxResult ObterListaFiliaisEmpresa(int codigoEmpresa, bool incluirTodas)
{
var retorno = new List<Filial>();

if (codigoEmpresa > 0)
{
this.SessaoCorrente.CodigoEmpresaCorrente = codigoEmpresa;

Empresa empresa = this.Repositorios.Empresa.ObterPelaChave(codigoEmp resa);

if (empresa != null)
retorno = empresa.Filiais.ToList();
}

if (incluirTodas)
retorno.Insert(0, new Filial() { Codigo = 0, Fantasia = "Todas as Filiais" });

return new AjaxResult(retorno);
}

public void SelecionarEmpresa(int codigoempresa)
{
this.SessaoCorrente.CodigoEmpresaCorrente = codigoempresa;

this.SessaoCorrente.EmpresaCorrente = this.Repositorios.Empresa.ObterPelaChave(codigoemp resa);
}

Daniil
May 11, 2012, 3:45 PM
Hi,

Does setting up

AutoLoad="false"
for the dsFiliaisMasterPage Store help?

romeu
May 11, 2012, 4:42 PM
Ok, it worked! Thanks a lot!


Hi,

Does setting up

AutoLoad="false"
for the dsFiliaisMasterPage Store help?