【发布时间】:2018-05-07 21:19:14
【问题描述】:
网络 API
[HttpPost] //Get Vendor Master
public HttpResponseMessage GetVendorMaster(dynamic inXml)
{
string typeids = inXml.inXml;
int TypeID = Convert.ToInt32(typeids);
return new HttpResponseMessage()
{
Content = new StringContent(clsCommonLib.DataTableToJSON(MasterDetailsBO.GetVendorMaster(TypeID)), System.Text.Encoding.UTF8, "application/json")
};
}
数据: "[{"ID":14,"journey_Name":"One Way"},{"ID":15,"journey_Name":"Two Way"},{"ID":16,"journey_Name":"Multi City "}]"
Ajax 方法:
function bind()
{
$.ajax({
type: "POST",
url: vUrlWithClass,
contentType: "application/json;",
data: param,
async: false,
dataType: "json",
success: function (data) {
var result = $.parseJSON(data.d)
console.log(data)
$.each(result, function (index, list) {
var rdb = "<tr><td><input id=rb" + this['Text'] + " type='radio' name='rbCategories' value=" + this['Text'] + " /><label for=lbl" + this['Text'] + ">" + this['Text'] + "</label></td></tr>";
table.append(rdb);
//$("#cphDashboard_ddlJourneytype").append($("<option></option>").val(list.ID).html(list.journey_Name));
})
},
error: function (result) {
console.log(result)
alert(result)
}
});
}
}
ASPX 代码:
<asp:RadioButtonList ID="rdbJourneyTypeAir" runat="server" RepeatDirection="Horizontal" CssClass="FormatRadioButtonList">
</asp:RadioButtonList>
但我无法使用单选按钮列表绑定数据
【问题讨论】:
-
您混淆了服务器端和客户端。 RadioButtonList 是服务器端。 ASP.NET 4.0 能够进行客户端数据绑定 ASP.NET AJAX 4.0 中的数据绑定 (msdn.microsoft.com/en-us/magazine/ee309508.aspx) 如果您不使用 .4.0,那么只需遍历数组并附加 html 元素即可到容器
-
您的方法以 Get 为前缀,并且您正在创建 Post,命名差异令人困惑。请更新以符合设计指南
-
绑定到单选按钮列表时遇到什么错误
-
无法将单选按钮列表与数据库绑定
标签: asp.net ajax radiobuttonlist