0

我正在尝试使用 AJAX 填充下拉列表,但我收到了方法错误 500。我花了一整天的时间尝试在几个论坛上找到的所有内容,但似乎没有任何帮助。

如果有人可以在这里帮助我,那就太好了。谢谢!

ddl.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ddl.aspx.cs" Inherits="TSS.Administrator.ddl" %>

<%@ Register TagPrefix="ajax" Namespace="AjaxControlToolkit" Assembly="AjaxControlToolkit" %>
<!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></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager runat="server">
    </asp:ScriptManager>
    <div>
        <asp:DropDownList ID="ddlCourseLevel" runat="server">
        </asp:DropDownList>
        <ajax:CascadingDropDown ID="ccdCourseLevel" runat="server" Category="CourseLevel"
            TargetControlID="ddlCourseLevel" PromptText="---Select CourseLevel" LoadingText="Loading Countries.."
            ServiceMethod="BC" ServicePath="~/WebServices/ws1.asmx">
        </ajax:CascadingDropDown>
    </div>
    </form>
</body>
</html>

ws1.asmx

<%@ WebService Language="C#" CodeBehind="ws1.asmx.cs" Class="TSS.ws1" %>

ws1.asmx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Specialized;
using System.Configuration;
using AjaxControlToolkit;
using System.Web.Script.Services;

namespace TSS
{
    /// <summary>
    /// Summary description for ws1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class ws1 : System.Web.Services.WebService
    {

        dbConnection dbConn = new dbConnection();

        [WebMethod]
        public CascadingDropDownNameValue[] BC(string knownCategoryValues, string category)
        {

            DataTable dt = new DataTable();

            //CourseLevelDAL _courseLevelDAL = new CourseLevelDAL();

            dt = Admin_Course_WebService.PopulateCourseLevel();

            //create list and add items in it by looping through dataset table
            List<CascadingDropDownNameValue> courseleveldetails = new List<CascadingDropDownNameValue>();
            foreach (DataRow dtrow in dt.Rows)
            {
                string Name = dtrow["Name"].ToString();
                string Id = dtrow["Id"].ToString();
                courseleveldetails.Add(new CascadingDropDownNameValue(Name, Id));
            }
            return courseleveldetails.ToArray();
        }
    }
}
4

1 回答 1

0

使用调试工具Fiddler,发现找不到Web Method BC,之所以找不到,是因为它是静态方法。我将其更改为公共并添加了属性 [System.Web.Script.Services.ScriptService]。有效!

于 2012-05-31T14:53:10.687 回答