Ajax 駆動のカスケード ドロップダウン リストを作成しようとしています。私が見つけた例はWebサービスを使用していますが、VS2010 Webサービスを使用していません。代わりに、MVC を使用すると考えました。MVC サービスをセットアップする方法を示した別のチュートリアルに従いましたが、繰り返しが機能しません。以前は Web サーバーや MVC サービスを行ったことがなかったので、それほど難しいことではないと思っていましたが、座礁してしまいました。誰かが私が間違ったことを指摘できますか? 「コンパイラ エラー メッセージ: CS0524: '場所': インターフェイスは型を宣言できません」というエラーが表示されます
以下のコードを参照してください。ありがとう。りしょう
[ServiceContract]
public interface ILocations
{
[OperationContract]
List<Locations> GetLocations(int ident);
[DataContract]
public class Locations <<- ERROR *******************************
{
int ident = 0;
string description = string.Empty;
[DataMember]
public int Ident
{
get { return ident; }
set { ident = value; }
}
[DataMember]
public string Description
{
get { return description; }
set { description = value; }
}
}
}
public class Locations : ILocations
{
SqlCommand cmd = new SqlCommand();
SqlConnection conn = new SqlConnection();
string connString = WebConfigurationManager.ConnectionStrings["dbLocations"].ToString();
List<ILocations.Locations>GetLocations(int ident)
{
cmd.Connection = new SqlConnection(connString);
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "sp_Location_Get_Children";
cmd.Parameters.Add("@pintParentIdent", SqlDbType.Int);
cmd.Parameters["@pintParentIdent"].Value = ident;
List<ILocations.Locations> _location = new List<ILocations.Locations>();
try
{
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dtLocations = new DataTable();
da.Fill(dtLocations);
if (dtLocations.Rows.Count > 0)
{
for (int i = 0; i < dtLocations.Rows.Count; i++)
{
ILocations.Locations _locInfo = new ILocations.Locations();
_locInfo.Ident = Convert.ToInt32(dtLocations.Rows[i]["ident"]);
_locInfo.Description = dtLocations.Rows[i]["description"].ToString();
_location.Add(_locInfo);
}
}
return _location;
}
catch (Exception ex)
{
cmd.Connection.Close();
throw;
}
}
}
<ajaxToolkit:CascadingDropDown ID="cddLocations" runat="server"
TargetControlID="ddlLocationDetail"
Category="description"
PromptText="Select Location"
LoadingText="Loading..."
ServicePath="~/App_Code/ILocations.cs"
ServiceMethod=""
ParentControlID="ddlRoomLocation"
SelectedValue="ident" />
<asp:DropDownList runat="server" ID="ddlRoomLocation" AppendDataBoundItems="True"
DataTextField="description" DataValueField="ident"
width="246px" CssClass="AssetMngnt-smallFont" AutoPostBack="true"
OnSelectedIndexChanged="ddlRoomLocation_OnSelectedIndexChanged" >
<asp:ListItem Value="-1" Selected="True">-- Select a Location -- </asp:ListItem>
<asp:ListItem Value="-2">-- All Printers --</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList Visible="false" runat="server" ID="ddlLocationDetail" AppendDataBoundItems="True"
DataTextField="description" DataValueField="ident"
width="246px" CssClass="AssetMngnt-smallFont" AutoPostBack="true"
OnSelectedIndexChanged="ddlLocationDetail_OnSelectedIndexChanged" >
<asp:ListItem Value="-1" Selected="True">-- Select a Detail --</asp:ListItem>
</asp:DropDownList>