我有一个wcf服务,用于在IIS 7的ASPX页面中填充级联下拉列表。该下拉列表获取数千个空选项标签,但没有数据。该服务不会引发错误。整个解决方案在桌面上的IDE中运行,但是在IIS上部署时,该服务无法正常工作。我怀疑这是IIS问题,但无法识别。
<snippet from aspx page>
<asp:DropDownList ID="ddCommercialServicesSiteName" runat="server" Width="150"></asp:DropDownList>
<ajaxToolkit:CascadingDropDown
ID="cddCommercialServicesSiteName" TargetControlID="ddCommercialServicesSiteName"
PromptText="Select" PromptValue="" Category="siteID"
ServicePath="~/ServiceDropDown.svc" ServiceMethod="GetCommercialSites"
LoadingText ="Loading..." runat="server"/>
<!-- ServiceDropDown.svc code -->
<%@ ServiceHost Language="C#" Debug="true" Service="ReportDashboard.ServiceDropDown" CodeBehind="ServiceDropDown.svc.cs" %>
公共列表GetCommercialSites(字符串knownCategoryValues,字符串contextKey)
{ 列出网站=新的List();
if (contextKey == null)
{
return sites;
} 字符串查询= @“选择DISTINCT ContactName AS Site,来自站点的ID”;
SqlCommand cmd = new SqlCommand(query);
using (SqlConnection con = new SqlConnection(conString))
{
con.Open();
cmd.Connection = con;
cmd.Parameters.Add("@account", SqlDbType.VarChar).Value = contextKey.ToString();
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
sites.Add(new CascadingDropDownNameValue
{
name = reader[0].ToString(),
value = reader[1].ToString(),
});
}
reader.Close();
con.Close();
}
}
return sites;
}
答案 0 :(得分:0)
尝试这种方法从阅读器中检索值。
List<MyModelClass> result = new List<MyModelClass>();
while (reader.Read())
{
object[] values = new object[3];
reader.GetValues(values);
MyModelClass model = new MyModelClass();
model.ID = values[0].ToString();
model.ValueProperty = values[1].ToString();
model.ValueProperty2 = values[2].ToString();
result.Add(model);
}
在您的View / aspx中运行jQuery来填充您的下拉菜单,
$("#dropdown").change(function () {
dropdown.append($("<option></option>").val("").html("Please wait ..."));
$.ajax({
url: "/api/CascadingData/GetSomeData/",
type: "GET",
dataType: "json",
data: { Id: Id },
success: function (d) {
dropdown.empty(); // Clear the list, including the please wait option
dropdown.append($("<option></option>").val('').html("Select an option..."));
$.each(d, function (i, ModelObject) {
dropdown.append($("<option></option>").val(ModelObject.Name).html(ModelObject.Value));
});
},
error: function () {
alert("Error in $('#dropdown').change!");
}
});
}