首先,我要做的是填充这样的下拉框:
<asp:DropDownList CssClass="ui dropdown" ID="drpGolfClub" runat="server"></asp:DropDownList>
有些价值观给了我高尔夫俱乐部的身份和名字。问题是,使用jQuery我似乎无法运行后面的vb文件中的代码。这一切看起来都像这样。 在aspx文件中:
function loadGolfClub()
{
alert('inside method');
//debugger;
$.ajax({
type: "POST",
url: "Register.aspx/LoadGolfClub",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: false,
success: function (Result) {
debugger;
Result = Result.d;
$('#<%=drpGolfClub.ClientID%>').empty();
$('#<%=drpGolfClub.ClientID%>').prepend("<option value='0'>" +"Select" + "</option>");
$.each(Result, function (key, value) {
$('#<%=drpGolfClub.ClientID%>').append($("<option></option>").val(value.GolfClubId).html(value.GolfClubName));
$('#<%=drpGolfClub.ClientID%>')[0].selectedIndex = 1;
});
alert("in sucess!");
},
failure: function () {
alert("Failed!");
}
});
}
后面添加了aspx文件的vb:
Imports System
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports Microsoft.AspNet.Identity
Imports Microsoft.AspNet.Identity.EntityFramework
Imports Microsoft.AspNet.Identity.Owin
Imports Owin
Imports System.Data
Imports System.Web.Services
Imports System.Reflection
Imports Golfbook.CoreLibrary
Imports Golfbook.CoreLibrary.Golfbook.Services
Public Class Register
Inherits System.Web.UI.Page
Shared objGCBO As New GolfClubBO()
Shared objGolfClubService As New Golfbook.CoreLibrary.Golfbook.Services.GolfClub.GolfClubDetails
Shared details As New List(Of GolfClubBO)()
Shared _loginName As String
Shared loginName As String
Private Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
End Sub
<WebMethod()>
<System.Web.Script.Services.ScriptMethod(ResponseFormat:=System.Web.Script.Services.ResponseFormat.Json)>
Public Shared Function LoadGolfClub() As GolfClubBO()
Dim details As New List(Of GolfClubBO)()
Try
details = objGolfClubService.LoadGolfClub()
Catch ex As Exception
End Try
Return details.ToList.ToArray()
End Function
End Class
我知道vb中的page_load正在运行,但它永远不会转到那里的函数。我现在尝试了“一切”,并且不知道该怎么做。功能中添加的警告框是触发,因此它开始运行
我知道JQuery正在运行,因为我已将som值添加到随机文本框中:$('#txtFirstName')。val('Martin');
关于这可能是什么原因的任何提示?
答案 0 :(得分:1)
如上所述,感谢ADyson,我的麻烦的答案是解决这个问题: 在〜/ App_Start / RouteConfig.cs里面改变:
settings.AutoRedirectMode = RedirectMode.Permanent;
To:
settings.AutoRedirectMode = RedirectMode.Off;
谢谢大家的回复!