PDA

View Full Version : [CLOSED] Razor/MVC custom search



machinableed
Mar 14, 2012, 7:44 AM
I'm looking to reproduce the example here: http://examples2.ext.net/#/Form/ComboBox/Custom_Search/ in MVC/Razor syntax but I'm having some trouble getting the method to trigger. Can you provide syntax? Is it necessary to use a .ashx file or can you set up a route directly to a controller method?

thanks

Daniil
Mar 14, 2012, 11:01 AM
Hi,


I'm looking to reproduce the example here: http://examples2.ext.net/#/Form/ComboBox/Custom_Search/ in MVC/Razor syntax but I'm having some trouble getting the method to trigger. Can you provide syntax?


Well, we have no such example on Razor.

Could you provide what you are able to achieve at the moment? Where exactly are facing a problem with syntax?



Is it necessary to use a .ashx file or can you set up a route directly to a controller method?


Sure, you can refererence a controller action setting up a respective Url.

machinableed
Mar 14, 2012, 11:06 AM
The issue I'm facing is that I can't get the controller method to trigger when I type in the box. The store and proxy I'm using works in a different example but I'm not sure how t get the combo box to trigger the controller. I can't actually post the code right now as I'm not at work, but I will do ASAP

machinableed
Mar 15, 2012, 7:27 AM
Here is the code I've been trying to use:


cnt.Add(Html.X().FieldContainer()
.Layout(LayoutType.HBox)
.Padding(10)
.Margins("0 0 0 0")
.Items(fields =>
{
fields.Add(Html.X().ComboBox()
.Width(700)
.FieldLabel("Customer/Organisation Name")
.Margins("0 0 4 0")
.LabelWidth(200)
.MinChars(1)
.DisplayField("OrganisationName")
.ValueField("OrganisationName")
.HideBaseTrigger(true)
.TypeAhead(false)
.Cls("form-label")
.ListConfig(Html.X().BoundList()
.LoadingText("Searching...")
.Height(200)
.ItemTpl(Html.X().XTemplate()
.Html("<div class=\"search-item\"><h3><span>{PartyID}</span>{OrganisationName}</h3>{OrganisationCode}</div>")
)
)
.Store(store => Html.X().Store()
.Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
.Url("/Party/GetOrganisations/")
.Reader(reader => reader.Add(Html.X().JsonReader()
.Root("data")
.TotalProperty("total")
))
))
.Model(model => model.Add(Html.X().Model()
.Fields(modelFields =>
{
modelFields.Add(Html.X().ModelField().Name("OrganisationName"));
modelFields.Add(Html.X().ModelField().Name("OrganisationCode"));
modelFields.Add(Html.X().ModelField().Name("PartyID"));
}) ))
)
);
})
);



The route to the /
Party/GetOrganisations method is definitely working as I can bind to other controls and also see the raw JSON if i enter it directly as the URL, but when I try to trigger it using the combobox as a "custom search" box as per the example, the method never gets triggered...

Daniil
Mar 15, 2012, 8:07 AM
Please ensure the code is wrapped in [CODE ] tags, see:
Forum Guidelines For Posting New Topics (http://forums.ext.net/showthread.php?3440)

Daniil
Mar 15, 2012, 1:08 PM
Thanks for the wrapping in
tags.

The problem lays here:
[CODE].Store(store =>
Html.X().Store()
...
)


It should be:

.Store(store =>
store.Add(Html.X().Store()
...
)
)

machinableed
Mar 18, 2012, 12:30 AM
Thanks it's working now... You can close this topic

machinableed
Mar 26, 2012, 1:38 AM
Hi there,

I had this functionality working with no problems, but since an SVN update I'm experiencing some strange behaviour. The method in the controller is still firing and obviously returning results as I can see the paging information changing, but the items don't appear in the drop down (the entire drop down is either blank after the initial result displays for a split second initially or the drop down doesnt expand as shown in the screenshot):

The code I'm using is:

containers.Add(Html.X().FieldContainer()
.Layout(LayoutType.Anchor)
.Margins("0 0 0 0")
.Width(900)
.Items(cnt =>
{
cnt.Add(Html.X().FieldContainer()
.Layout(LayoutType.HBox)
.Padding(10)
.Margins("0 0 0 0")
.Items(fields =>
{
fields.Add(Html.X().ComboBox()
.Width(700)
.FieldLabel("Customer/Organisation Name")
.ID("cmbCustomer")
.Margins("0 0 4 0")
.LabelWidth(200)
.PageSize(20)
.Note("Type Organisation Name to search and select an organisation. (*) to show all")
.MinChars(1)
.DisplayField("DisplayName")
.ValueField("PartyID")
.HideBaseTrigger(true)
.TypeAhead(false)
.Cls("form-label")
.ListConfig(Html.X().BoundList()
.LoadingText("Searching...")
.Height(200)
.ItemTpl(Html.X().XTemplate()
.Html("<div class=\"search-item\"><h3><span>{PartyID}</span>{DisplayName}</h3>{OrganisationCode}</div>")
)
)
.Store(store => store.Add(Html.X().Store()
.Proxy(proxy => proxy.Add(Html.X().AjaxProxy()
.Url("/Party/GetOrganisations/")
.Reader(reader => reader.Add(Html.X().JsonReader()
.Root("data")
.TotalProperty("total")
))
))
.Model(model => model.Add(Html.X().Model()
.Fields(modelFields =>
{
modelFields.Add(Html.X().ModelField().Name("DisplayName"));
modelFields.Add(Html.X().ModelField().Name("OrganisationCode"));
modelFields.Add(Html.X().ModelField().Name("PartyID"));
})
))
))
);
})
);
})
);
})

machinableed
Mar 26, 2012, 3:31 AM
I have done a further test by referencing the previous 2.0 beta dll (as released a couple of weeks ago) and this functionality works again - there is definitely something broken in the latest build...

Daniil
Mar 26, 2012, 4:35 AM
What is a response of a controller action?

Could you also provide the code of a controller action to reproduce the problem?

machinableed
Mar 26, 2012, 4:59 AM
The controller code calls a WCF service and returns a StoreResult. The code is as follows:


public StoreResult GetOrganisations()
{
StoreResult response = new StoreResult();
string filter = HttpContext.Request["query"];

int totalCount = 0;
PartyManagerServiceClient pmService = new PartyManagerServiceClient();

List<OrganisationVO> organisations = (List<OrganisationVO>)MemoryCache.Default["OrganisationVOs"];

List<Organisation> orgs = new List<Organisation>();
if (organisations == null)
{
organisations = new List<OrganisationVO>();
orgs = pmService.GetOrganisationsByName("", 0, 4000, ref totalCount);
foreach (Organisation org in orgs)
{
OrganisationVO orgVO = new OrganisationVO();
orgVO = Mapper.ToViewObject(org);
organisations.Add(orgVO);
}

MemoryCache.Default.AddOrGetExisting("OrganisationVOs", organisations, DateTime.Now.AddMinutes(10));
}

List<OrganisationVO> data = new List<OrganisationVO>();
data = organisations.ToList();

if (!string.IsNullOrEmpty(filter) && filter != "*")
{
data.RemoveAll(filterOrg => !filterOrg.DisplayName.ToLower().StartsWith(filter .ToLower()));
}

response.Data = data;
response.Total = data.Count;
return response;

}

OrganisationVO:


public class OrganisationVO
{
public int PartyID { get; set; }
public string OrganisationCode { get; set; }
public List<string> OrganisationNames { get; set; }
public string DisplayName { get; set; }
public bool IsCustomer { get; set; }
public bool IsSupplier { get; set; }

public OrganisationVO()
{
OrganisationNames = new List<string>();
}
}

public class OrganisationVOCollection : List<OrganisationVO>
{}

The other stuff is defined in the contracts/proxies from the WCF service. As I said this stuff works perfectly with the previous beta build - it's just the update I did this morning that seems to have broken it...

Daniil
Mar 26, 2012, 5:08 AM
Ok, thanks.

What is a response? It should help us to reproduce the problem.

machinableed
Mar 26, 2012, 5:19 AM
The response is basically list of OrganisationVO's as defined above. Examples:

DisplayName "1-Stop Connections" string
IsCustomer false bool
IsSupplier false bool
OrganisationCode "1SC" string
PartyID 23871 int


DisplayName "AAPT" string
IsCustomer false bool
IsSupplier false bool
OrganisationCode "APT" string
PartyID 20880 int

there is also a OrganisationNames collection but it's irrelevant to this I think - it's basically a list of organisation name objects but they are not used to bind to the combobox.

Daniil
Mar 26, 2012, 10:05 AM
Does setting up

.AutoLoad(false)
for the Store solve the problem?

machinableed
Mar 26, 2012, 11:56 PM
thanks Daniil! .Autoload(false) fixed the problem.

Daniil
Mar 27, 2012, 9:02 AM
Good. Though, at the first glance there is a bug.

I was able to reproduce the problem with a simple example below.

Just type something into the ComboBox - a JS error will occur.

Setting AutoLoad="false" solves the problem, but I think this is a work-around, not a fix.

We are investigating further.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Store_ReadData(object sender, StoreRefreshDataEventArgs e)
{
Store store = sender as Store;
store.DataSource = new object[]
{
new object[] { "1", "item1" },
new object[] { "2", "item2" },
new object[] { "3", "item3" }
};
store.DataBind();
}
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:ComboBox
runat="server"
MinChars="1"
PageSize="1"
Width="300">
<Store>
<ext:Store
runat="server"
OnReadData="Store_ReadData"
AutoLoad="true">
<Proxy>
<ext:PageProxy>
<Reader>
<ext:ArrayReader />
</Reader>
</ext:PageProxy>
</Proxy>
<Model>
<ext:Model runat="server">
<Fields>
<ext:ModelField Name="value" />
<ext:ModelField Name="text" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</form>
</body>
</html>

Daniil
Mar 27, 2012, 2:12 PM
This bug comes from ExtJS. We decided to wait its next release.

Daniil
May 01, 2012, 1:56 PM
The bug with

AutoLoad="true"
is gone.

Here is the related thread on Sencha forums:
http://www.sencha.com/forum/showthread.php?191149